无法使用修改后的 LLE、hessian LLE 和局部切线 Space 对齐分配那么多内存

Unable to allocate that much memory using modified LLE, hessian LLE and Local Tangent Space Alignment

你好,

我正在尝试在外部数据集上使用 LLE 和 LLE 的其他方法,如修改、hessian 和 ltsa(您可以在此处找到它:https://www.kaggle.com/mlg-ulb/creditcardfraud) 我让它与 LLE 一起工作,但修改后的版本肯定需要太多内存。 例如:

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)