【问题标题】:Scikit learn deviations in accuracyScikit 学习精度偏差
【发布时间】:2018-05-28 08:54:58
【问题描述】:

我正在使用 scikit-learn 集成分类器进行分类。我有单独的训练和测试数据集。当我使用相同的数据集并使用机器学习算法进行分类时,我得到了一致的准确度。不一致性仅发生在集成分类器的情况下。我什至将 random_state 设置为 0。

bag_classifier = BaggingClassifier(n_estimators=10,random_state=0)
bag_classifier.fit(train_arrays,train_labels)   
bag_predict = bag_classifier.predict(test_arrays)  
bag_accuracy = bag_classifier.score(test_arrays,test_labels)   
bag_cm = confusion_matrix(test_labels,bag_predict)   
print("The Bagging Classifier accuracy is : " ,bag_accuracy)   
print("The Confusion Matrix is ")  
print(bag_cm)

【问题讨论】:

  • 也发布您的代码。
  • 在您使用的所有方法或类中查找random_state 参数并设置它。另外,请发布完整的代码。
  • 请查看这些与您的问题重复的问题:Question1Question2

标签: scikit-learn classification


【解决方案1】:

对于同一个模型,您通常会发现不同的结果,因为每次在训练期间执行模型时,训练/测试拆分都是随机的。您可以通过将种子值分配给训练/测试拆分来重现相同的结果。

train, test = train_test_split(your data , test_size=0.3,  random_state=57)

在每一轮训练中保持相同的random_state 值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-27
    • 1970-01-01
    • 1970-01-01
    • 2016-12-24
    • 2018-10-21
    • 2016-12-20
    • 2017-04-27
    • 2015-12-22
    相关资源
    最近更新 更多