python - 如何从 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
. 目前我只能得到均方误差,但是如何比较“实际”和“预测”集以查看“实际”列表中的错误百分比。
解决方案
推荐阅读
- r - 从向量中选择随机元素,但每次都排除某些数字
- sql - SQL - Error converting data type varchar to numeric
- r - 将字符名称变量放入数据框中
- reactjs - 如何使用键获取对列表中元素的引用?
- node.js - 添加或更新深度嵌套模型实例的更简单方法
- python - Python 美丽的汤刮,Newegg
- mysql - 使用主机网络运行具有不同端口的多个 mysql 容器
- javascript - 如何获取 HTML 集合的第一个元素?
- javascript - Suitescript、nlapiRequestURL 无法将 JSON 从 URL 转换为对象/数组
- python - 这样的时间怎么写