我想为我的K-NN打印10个最高概率预测(不仅是该值的索引)
到目前为止,我使用了此代码,但是Argsort产生了索引而不是值。
from sklearn.neighbors import NearestNeighbors
from sklearn.neighbors import KNeighborsClassifier
kNN = KNeighborsClassifier(n_neighbors = 3)
kNN = kNN.fit(X_train,y_train.values.ravel())
probs = kNN.predict_proba(X_test)
best_n = np.argsort(probs, axis=1)[:,-10:]
我正在预测文章ID号,因此我基本上希望为每个客户提供10个最佳文章建议。
An example of the output would be:
Customer_id | Article_id Pred |
---|---|
2a3c236907d | 673531001 |
But I would like the top 10 article predictions, so for example:
Customer_id | Article_id Pred |
---|---|
2a3c236907d | 673531001 464277014 108775044 108775051 .... |
I used this code so far, but argsort produces the indexes rather than the value.
from sklearn.neighbors import NearestNeighbors
from sklearn.neighbors import KNeighborsClassifier
kNN = KNeighborsClassifier(n_neighbors = 3)
kNN = kNN.fit(X_train,y_train.values.ravel())
probs = kNN.predict_proba(X_test)
best_n = np.argsort(probs, axis=1)[:,-10:]
I am predicting article id numbers, so I basically want the 10 best article recommendations for each customer.
An example of the output would be:
Customer_id | Article_id Pred |
---|---|
2a3c236907d | 673531001 |
But I would like the top 10 article predictions, so for example:
Customer_id | Article_id Pred |
---|---|
2a3c236907d | 673531001 464277014 108775044 108775051 .... |
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论