如何计算预测的准确性?

时间:2020-09-13 20:37:34

标签: python classification prediction knn

我已经从包含一些分类参数的数据集中创建了一个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

1 个答案:

答案 0 :(得分:0)

最简单的方法是:

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