【问题标题】:My Code uses over 25GB of Ram and Crashes我的代码使用超过 25GB 的内存和崩溃
【发布时间】:2020-06-12 00:18:42
【问题描述】:

所以我使用 Extra Trees Classifier 来查找我的数据集中的特征重要性,它由 13 列和大约 1000 万行组成。我在上面运行了椭圆信封,隔离森林,一切都很好,甚至不到 10 GB。我在 jupyter 笔记本上运行我的代码,即使我将它设置为 low_memory=True,它也会给我内存错误。我尝试了大约 25GB 内存的 Google COlab,但仍然崩溃,我现在很困惑。

代码:

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

%matplotlib inline


from sklearn.ensemble import ExtraTreesClassifier 


from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
from google.colab import auth
from oauth2client.client import GoogleCredentials


# Authenticate and create the PyDrive client.
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(gauth)



# Loading First Dataframe

link = '...'

fluff, id = link.split('=')
print (id) # Verify that you have everything after '='
downloaded = drive.CreateFile({'id':id}) 
downloaded.GetContentFile('Final After Simple Filtering.csv')  
df = pd.read_csv('Final After Simple Filtering.csv',index_col=None,low_memory=True)
#df = df.astype(float)


ExtraT = ExtraTreesClassifier(n_estimators = 100,bootstrap=False,n_jobs=1) 

y=df['Power_kW']

del df['Power_kW']

X=df


ExtraT.fit(X,y)

feature_importance = ExtraT.feature_importances_ 

feature_importance_normalized = np.std([tree.feature_importances_ for tree in ExtraT.estimators_], axis = 1)

plt.bar(X.columns, feature_importance) 
plt.xlabel('Lable') 
plt.ylabel('Feature Importance') 
plt.title('Parameters Importance') 
plt.show()  

谢谢

【问题讨论】:

  • "...并且仍然崩溃" - 任何特定的错误消息?
  • 在 Jupyter Notebook 上显示:“MemoryError: could not allocate 28806479872 bytes`”和在 Google Colab 上:“您的会话在使用 Google Collab 中的所有可用 RAM 后崩溃”
  • 请在您的帖子中分享整个错误消息。既然我们不能有一个简单的minimal reproducible example,你有没有做过任何分析?
  • @AMC 似乎当我将 max_depth 设置为低于或等于 10 的任何位置时,它开始正常运行,任何相关的事情都会给我带来内存错误。我还设置了 n_jobs=1

标签: python pandas dataframe machine-learning jupyter-notebook


【解决方案1】:

我之前遇到过同样的错误,我解决了。

更改运行时类型 GPU 比 CPU 更快,所以它会有所帮助。但如何做到这一点?请按照以下步骤操作:

确保您使用 25GB 而不是 12GB 的 RAM。 不要忘记 Colab 是免费和限量版。 如果仍有问题,请告诉我,我会尽快为您提供帮助。

【讨论】:

    猜你喜欢
    • 2020-09-02
    • 1970-01-01
    • 2010-10-02
    • 2013-01-30
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 2016-08-03
    • 1970-01-01
    相关资源
    最近更新 更多