簡體   English   中英

將稀疏矩陣擬合到kNN模型時出現MemoryError

[英]MemoryError while fitting a sparse matrix to kNN model

在運行以下代碼時,我在最后一行遇到了MemoryError:

from sklearn.neighbors import KNeighborsClassifier
clf = KNeighborsClassifier(n_neighbors=7)
clf.fit(train_X, y_train)
y_pred_clf = clf.predict(test_X)

test_X<10852x112 sparse matrix of type '<class 'numpy.float64'>' with 97668 stored elements in Compressed Sparse Row format><10852x112 sparse matrix of type '<class 'numpy.float64'>' with 97668 stored elements in Compressed Sparse Row format>

有什么建議么?

一種方法是使用一批數據, 第二種方法是對KNN模型使用不同的算法:

clf = KNeighborsClassifier(n_neighbors=5,algorithm='kd_tree').fit(X_train, Y_train)
y_pred_clf = clf.predict(test_X)

默認情況下,該模型為algorithm ='brute',而蠻橫的false占用過多內存。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM