2017-12-14 8 views
-3

분류를 위해 scikit-learn 앙상블 분류기를 사용하고 있습니다. 별도의 교육 및 테스트 데이터 세트가 있습니다. 동일한 데이터 세트를 사용하고 기계 학습 알고리즘을 사용하여 분류하면 일관된 정확도를 얻게됩니다. 불일치는 앙상블 분류 자의 경우에만 해당됩니다. 난 0Scikit 정확도의 편차를 배웁니다.

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) 
+1

코드도 게시하십시오. –

+1

사용하는 모든 메소드 나 클래스에서'random_state' 매개 변수를 찾아서 설정하십시오. 또한 전체 코드를 게시하십시오. –

+1

다음 질문을 참조하십시오 : [질문 1] (https://stackoverflow.com/questions/28673442/getting-different-result-each-time-i-run-a-linear-regression-using-scikit) 및 [질문 2] (https://stackoverflow.com/questions/43901083/sgdclassifier-giving-different-accuracy-each-time-for-text-classification) –

답변

0

에 random_state를 설정 한 모델이 훈련 도중 실행될 때마다이 기차/테스트 분할 무작위이기 때문에 일반적으로 같은 모델의 다른 결과를 찾을 수 있습니다. 열차/테스트 분할에 시드 값을 제공하여 동일한 결과를 재현 할 수 있습니다.

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

각 훈련 단계마다 동일한 random_state 값을 유지하십시오.