如何计算预测的准确性?

问题描述

我已经从包含一些分类参数的数据集中创建了一个excel。然后,我创建了一个测试数据集,并对这些数据进行了分类。现在,我对所有测试数据都有预测了,但是如何找到这些预测的准确性呢?

df = pd.read_excel(r"excellocation")
df_model = df.copy()
scaler = StandardScaler()
features =  [[feature1,feature2......]]
for feature in features:
    df_model[feature] = scaler.fit_transform(df_model[feature])
knn = KNeighborsClassifier()
x = df_model.drop(columns=['class'],1)
y = df_model['class']
knn.fit(x,y)
clf= neighbors.KNeighborsClassifier()
clf.fit(x,y)
for example in test_data:
     prediction = clf.predict(example)
#####i need accuracy of this prediction

解决方法

最简单的方法是:

preds = clf.predict(test_data)
accuracy = np.mean(preds == test_data)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...