def random_forest_classify(my_train_data, my_train_label, my_test_data, estimators):
clf = RandomForestClassifier(n_estimators=estimators)
scores = cross_validation.cross_val_score(clf, my_train_data, my_train_label, cv=5)
print("random forest(%d) accuracy: %0.3f (+/- %0.3f)" % (estimators, scores.mean(), scores.std() * 2))
clf.fit(my_train_data, my_train_label)
my_test_label = clf.predict(my_test_data)
file_name = "random_forest_%d.csv" % estimators
save_data(my_test_label, file_name)
评论列表
文章目录