首页 > 解决方案 > 如何从 KNeighboorsRegressor (scikit-learn) 获得成功率(准确度)

问题描述

import pandas
with open('aotiz.csv', 'r') as csvfile:
    aotiz = pandas.read_csv(csvfile)


test = aotiz.loc[16:7000]
# Generate the train set with the rest of the data.
train = aotiz.loc[7000:7006]

x_columns = distance_columns
y_column = ["PM2.5"]

from sklearn.neighbors import KNeighborsRegressor
from sklearn.metrics import mean_squared_error
from sklearn import metrics

knn = KNeighborsRegressor(n_neighbors=6)
# Fit the model on the training data.
knn.fit(train[x_columns], train[y_column])
# Make point predictions on the test set using the fit model.
predictions = knn.predict(test[x_columns])

actual = test[y_column]

mse = (((predictions - actual) ** 2).sum()) / len(predictions)

print(mse)

我想知道如何从scikit-learn. 目前我只能得到均方误差,但是如何比较“实际”和“预测”集以查看“实际”列表中的错误百分比。

标签: pythonscikit-learn

解决方案


推荐阅读