【问题标题】:How to find the predition accuracy in precentage using regression model in python如何在python中使用回归模型找到预测准确率的百分比
【发布时间】:2020-01-24 09:08:17
【问题描述】:

这里我尝试使用 LSTM 回归模型根据实际值来预测值。预测值后,我需要找到预测值与实际值的预测准确率百分比。

我试过了,但它给了我很大的负值。

这是我的代码:

pred=model.predict(x_test)
pred = scaler_y.inverse_transform(np.array(pred).reshape ((len(pred), 1)))
real_test = scaler_y.inverse_transform(np.array(y_test).reshape ((len(y_test),1))).astype(int)
pred = pred[:,0]
real_test = real_test[:,0]

from sklearn.metrics import accuracy_score
from sklearn.metrics import mean_squared_error
accuracy_regression = mean_squared_error(real_test, pred) 
print(accuracy_regression)
accuracy = 1-np.sqrt(accuracy_regression)
print("Prediction Accuracy: %.2f%%" % (accuracy*100))

然后输出:

394.2002447320037
Prediction Accuracy: -1885.45%

这是错误的。谁能帮我解决这个错误?

【问题讨论】:

  • 准确率是一个分类指标。对于回归,尝试 r2_score、mean_square_error 等。
  • @ShwetaChandel 你能给我举个例子吗,实际上我试过了,但没有达到正确的准确度水平。如果你没事的话。谢谢
  • 只需将 accuracy_score 替换为 r2_score。 scikit-learn.org/stable/modules/generated/…
  • @ShwetaChandel 知道了。谢谢。

标签: python regression lstm


【解决方案1】:

我想你正在使用 scikit-learn ? 因此,均方误差 (MSE) 计算出与平方(二次)误差或损失的期望值相对应的风险度量 (more informations here)

如果您想知道模型的准确度得分,可以使用以下函数:

sklearn.metrics.accuracy_score(y_true, y_pred, normalize=True, sample_weight=None)

您可以在 scikit-learn here 中找到有关指标的更多信息

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 2021-10-18
    • 2021-05-15
    • 1970-01-01
    • 2020-11-17
    • 2018-02-09
    • 2018-03-05
    • 2021-01-16
    • 2013-12-25
    相关资源
    最近更新 更多