我有一个有9000行(文档)和1810个cols (术语)的文档-术语矩阵。我已经应用PCA进行降维,输出的是一个9000x200的矩阵。
我的目的是对这些数据进行聚类,下一步是应用一些距离度量,比如sklearn的cosine_similarity。
如果我直接在我的DT矩阵上运行cosine_similarity (这显然是稀疏的),那么一切都很好。但是,如果我尝试对PCA得到的矩阵运行cosine_similarity,让我们称其为reducted_dtm,那么我在PyCharm中得到一个内存错误:
RecursionError: maximum recursion depth exceeded while calling a Python object
Process finished with exit code -1073741571 (0xC00000FD)下面是我的代码(dtm是我的文档-术语矩阵,我的代码实际上接受转置后的术语-文档矩阵tdm作为输入):
dtm = tdm.T
# scale dtm in range [0:1] to better variance maximization
scl = MinMaxScaler(feature_range=[0, 1])
data_rescaled = scl.fit_transform(dtm)
# Fitting the PCA algorithm with our Data
pca = PCA(n_components=n).fit(data_rescaled)
data_reducted = pca.transform(data_rescaled)
# for continuity with my pipeline I need to
# return the TDM, so i transpose again
dtm_reducted = pd.DataFrame(data_reducted)
# Here apply cosine similarity
cs = cosine_similarity(dtm_reducted)
cs_pd = pd.DataFrame(cs)发布于 2020-03-31 00:27:44
天哪,我意识到,实际上在我的代码中,我是从一个名为‘cosine_ cosine_similarity’的函数中调用cosine_similarity (sklearn)的。这导致了无限的递归循环。
https://stackoverflow.com/questions/60934156
复制相似问题