无法使用修改后的LLE、Hessian LLE和局部切线空间对齐分配足够的内存

你好

我在尝试对一个外部数据集(你可以在这里找到:https://www.kaggle.com/mlg-ulb/creditcardfraud)使用LLE和其他LLE方法,如修改后的、Hessian和LTSA。我已经成功使用了LLE,但修改版本显然需要太多的RAM。例如:

def clean_dataset(df):    assert isinstance(df, pd.DataFrame), "df needs to be a pd.DataFrame"    df.dropna(inplace=True)    indices_to_keep = ~df.isin([np.nan, np.inf, -np.inf]).any(1)    return df[indices_to_keep].astype(np.float64)data = pd.read_csv('C:/Users/yazar/Downloads/creditcardfraud/creditcard.csv')clean_dataset(data)X_features = data.drop('Class', axis=1)y_targets = data['Class']clf = manifold.LocallyLinearEmbedding(n_neighbors=n_neighbors, n_components=2, method='modified')clf.fit(X=X_features, y=y_targets)t0 = time()print("Done. Reconstruction error: %g" %clf.reconstruction_error_)X_mllecf=clf.transform(X_features)

会产生以下错误:

MemoryError: Unable to allocate 604. GiB for an array with shape (284807, 284807) and data type float64

我如何才能减少所需的内存,或者如果必要的话,缩小数据集以获得一些结果?


回答:

我的解决方案是通过选择数据的随机样本来减少数据框架,使用以下函数:

sample = data.sample(n=3000, random_state=1)

但使用它时,你需要重置索引号,否则你的绘图函数将无法工作:

sample = sample.reset_index(drop=True)

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注