【问题标题】:How to calculate accuracy of prediction? [duplicate]如何计算预测的准确性? [复制]
【发布时间】:2020-12-31 15:31:07
【问题描述】:

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

【问题讨论】:

    标签: python classification prediction knn


    【解决方案1】:

    最简单的方法是:

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

    【讨论】:

    • 感谢您的回答!但是我在预测步骤之前有很多计算。另外,我需要每个预测的准确性。你知道方法吗?
    • 正如我所展示的accuracy = np.mean(preds==true_data)
    猜你喜欢
    • 2012-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-12
    • 2016-06-03
    • 2019-02-14
    • 2021-08-03
    • 2021-08-03
    相关资源
    最近更新 更多