用RandomizedSearchCV想给n_estimators扫一个参数,但是设置啥的都没有变,为什么每次运行的结果扫出来的最佳参数结果不一样
from sklearn.model_selection import RandomizedSearchCV
#树的个数
n_estimators = [int(x) for x in range(10, 1000, 10)]
#bootstrap = [True, False]
#max_depth = [int(x) for x in range(10, 100, 10)]
param_random = {
'n_estimators': n_estimators,
}
rf = RandomForestClassifier()
rf_random = RandomizedSearchCV(estimator=rf, param_distributions=param_random, cv=5, verbose=2,#输出每一行的记录
random_state=42)
rf_random.fit(X,y)
best_estimator = rf_random.best_estimator_
def Calculation_accuracy(estimator, test_x, test_y):
pre_y = estimator.predict(test_x)
error = abs(pre_y - test_y).mean()
accuraccy = ((1 - abs(pre_y - test_y)/test_y)*100).mean()
return error, accuraccy
error, accuraccy = Calculation_accuracy(best_estimator,X,y)
print(error, accuraccy)
print(rf_random.best_params_)
无
无
想要让每次得到的结果一样