Created
November 28, 2016 20:53
-
-
Save gilesc/762e885aa0c625ec99feaa3cc4b271cb to your computer and use it in GitHub Desktop.
Sklearn PCA potential memory leak
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import psutil | |
import numpy as np | |
import sklearn.decomposition | |
def memory_usage(): | |
return psutil.Process(os.getpid()).memory_info().rss / 1024 ** 2 | |
def pca(X): | |
model = sklearn.decomposition.PCA(n_components=5) | |
pc = model.fit_transform(X) | |
del model | |
return pc | |
if __name__ == "__main__": | |
X = np.random.random((1000,10000)) | |
for i in range(100): | |
pc = pca(X) | |
del pc | |
print(i, int(memory_usage()), "MB") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment