【发布时间】: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