我在python中执行RandomForest和AdaBoost回归
我的结果不可重复[我的预测每次都使用相同的数据和代码进行更改]
seed = np.random.seed(22)
rng = np.random.RandomState(1)
param_grid = {'n_estimators': [10, 100, 1000]}
model_rfr = GridSearchCV(RandomForestRegressor(random_state = rng), param_grid, cv=3, n_jobs=-1, verbose=1)
model_rfr.fit(train_x1,train_y1)
test_rfr = model_rfr.predict(test_y1)
param_grid = {"n_estimators":[100,500],"learning_rate":list(np.linspace(0.01,1,10)),"loss":["linear", "square", "exponential"]}
model_adr = RandomizedSearchCV(AdaBoostRegressor(DecisionTreeRegressor()), param_grid,n_jobs=-1,n_iter=10,cv=3,random_state = rng)
model_adr.fit(train_x1,train_y1)
test_adr = model_adr.fit(test_y1)
这里是test_adr& test_rfr值每次都改变,我运行我的代码。
请使用回归的任何样本数据。但请建议如何使我的结果可重复。
答案 0 :(得分:-1)
感谢您的贡献。请找到可重现的结果代码。
seed = np.random.seed(22)
rng = np.random.RandomState(1)
param_grid = {'n_estimators': [10, 100, 1000]}
model_rfr = GridSearchCV(RandomForestRegressor(random_state = rng), param_grid, cv=3, n_jobs=-1, verbose=1)
model_rfr.fit(train_x1,train_y1)
test_rfr = model_rfr.predict(test_y1)
param_grid = {"n_estimators":[100,500],"learning_rate":list(np.linspace(0.01,1,10)),"loss":["linear", "square", "exponential"]}
model_adr = RandomizedSearchCV(AdaBoostRegressor(DecisionTreeRegressor(random_state = rng)), param_grid,n_jobs=-1,n_iter=10,cv=3,random_state = rng)
model_adr.fit(train_x1,train_y1)
test_adr = model_adr.predict(test_x1)