【问题标题】:how to find accuracy while dealing with pickle files in python?如何在 python 中处理泡菜文件时找到准确性?
【发布时间】:2020-05-27 05:16:12
【问题描述】:

这是我的代码。在这里,我试图使用梯度提升回归器来预测故障数量。

from sklearn.ensemble import GradientBoostingRegressor
# GradientBoostingRegressor
regr3 = GradientBoostingRegressor(random_state=0)
regr3.fit(X_train, y_train.values.ravel())    

pkl_filename = "GradientBoostingRegressor.pkl"
    with open(pkl_filename, 'wb') as file:
        pickle.dump(regr3, file)

    # Load from file
    with open(pkl_filename, 'rb') as file:
        pickle_model = pickle.load(file)

    score = pickle_model.score(X_test, y_test)
    print("Test score: {0:.2f} %".format(100 * score))
    Ypredict = pickle_model.predict(X_test)
    print(Ypredict)
    a= Ypredict.reshape(-1,1)
    accuracy_score= pickle_model.score(a, y_test)
    print(accuracy_score)

在执行时,分数很容易计算 (99.69%)。但准确度没有计算。我还有另一个疑问——我们能否选择一个 test_score 最高的模型作为最佳模型。还是我应该找到准确度并找到准确度最高的那个来获得模型? 遇到的错误是----“模型的特征数必须与输入匹配。模型n_features为52,输入n_features为1”

【问题讨论】:

标签: python scikit-learn pickle


【解决方案1】:

accuracy_score 用于检查分类模型的性能。由于您使用的是回归模型,因此您应该使用 r2 分数、mse 或 rmse 分数。更多信息请在此处查看所有model evaluation functions

例如

from sklearn.metrics import r2_score
r2_score(a, y_test)

【讨论】:

  • 先生,我也做过同样的事情。但出现错误.. ValueError:分类指标无法处理连续目标和多类目标的混合
  • @devikasathyan accuracy_score 用于基本分类模型。您正在使用回归模型。您应该使用 r2、mse 或 rmse 检查您的模型性能。检查此链接scikit-learn.org/stable/modules/model_evaluation.html
  • 谢谢您,先生...我解决了...谢谢您的时间,先生
猜你喜欢
  • 1970-01-01
  • 2021-05-12
  • 2019-10-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-07
相关资源
最近更新 更多