【发布时间】:2017-11-01 10:16:58
【问题描述】:
我对 sklearn 有疑问,不知道我做错了什么。
我想将网站分为 3 个类别:“金融”、“IT”、“医疗保健”
我对每个网站都有几个指标(基本上是一个关键字列表),我最终使用了一个 knn 分类器:
# fit the classifier
>>> y = array(['financial_services', 'health_care', 'information_technology'], dtype=object)
>>> X.shape = (3L, 571L)
neigh = KNeighborsClassifier(n_neighbors=3)
neigh.fit(X, y)
# predict the result for some website (predict is a matrix with my features)
print(neigh.predict(predict))
>>> ['financial_services'] # predict the first category
print(neigh.kneighbors(predict)) # get the "distances" to each category
>>> (array([[ 2323819.25162006, 2323841.23289028, 2323852.69883011]]), array([[2, 0, 1]], dtype=int64)) # we can see that this website is closer to the category #2, which is IT
我尝试预测其他网站的类别,但我总是使用neigh.predict 得到相同的预测,例如“金融服务”,而使用距离得到不同的值(使用neigh.predict)。
我错过了什么?
【问题讨论】:
标签: python python-2.7 scikit-learn