【问题标题】:Unable to allocate that much memory using modified LLE, hessian LLE and Local Tangent Space Alignment无法使用修改后的 LLE、hessian LLE 和局部切线空间对齐来分配那么多内存
【发布时间】:2021-01-11 15:29:11
【问题描述】:

你好

我正在尝试在外部数据集上使用 LLE 和其他 LLE 方法,例如 modified-、hessian- 和 ltsa(您可以在此处找到它:https://www.kaggle.com/mlg-ulb/creditcardfraud) 我让它与 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

如何最小化所需的内存,或者在必要时最小化数据集以获得一些结果?

【问题讨论】:

    标签: python dataframe machine-learning scikit-learn dimensionality-reduction


    【解决方案1】:

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

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

    但是使用它你必须重置索引号,否则你的绘图功能将无法工作:

    sample = sample.reset_index(drop=True)
    

    【讨论】:

      猜你喜欢
      • 2021-11-06
      • 1970-01-01
      • 2011-09-06
      • 1970-01-01
      • 2021-09-26
      • 2011-04-29
      • 2012-08-12
      • 1970-01-01
      • 2021-10-13
      相关资源
      最近更新 更多