Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/348.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
随机森林回归器-Python不可复制_Python_Scikit Learn_Regression_Random Forest_Reproducible Research - Fatal编程技术网

随机森林回归器-Python不可复制

随机森林回归器-Python不可复制,python,scikit-learn,regression,random-forest,reproducible-research,Python,Scikit Learn,Regression,Random Forest,Reproducible Research,我试图检查n_估计量对随机森林回归器性能的影响 seed = np.random.seed(1962) rng = np.random.RandomState(1962) np.random.seed(1962) estimators = [pow(2,3),10,pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,8),500,pow(2,9),pow(2,10),pow(2,11)] #oob_train = {} train_acc = {} test_

我试图检查n_估计量对随机森林回归器性能的影响

seed = np.random.seed(1962)
rng = np.random.RandomState(1962)

np.random.seed(1962)

estimators = [pow(2,3),10,pow(2,4),pow(2,5),pow(2,6),pow(2,7),pow(2,8),500,pow(2,9),pow(2,10),pow(2,11)]
#oob_train = {}
train_acc = {}
test_acc = {}
for w in range(0,len(estimators),1):
    modelrfe = RandomForestRegressor(n_estimators = estimators[w],random_state=rng, n_jobs = -1)
    model_params = estimators[w]
    modelrfe.fit(train_x1,train_y1)
    train_acc[model_params] = mean_absolute_error(scale_data.inverse_transform(train_y1.reshape(-1,1)),scale_data.inverse_transform(modelrfe.predict(train_x1).reshape(-1,1)))
    test_acc[model_params] = mean_absolute_error(scale_data.inverse_transform(test_y1.reshape(-1,1)),scale_data.inverse_transform(modelrfe.predict(test_x1).reshape(-1,1)))



train_acc = pd.DataFrame(train_acc.items())
train_acc.columns = ['keys','Trainerror']
test_acc = pd.DataFrame(test_acc.items())
test_acc.columns = ['keys','Testerror']
error_df3 = pd.merge(train_acc, test_acc, on='keys')
error_df3 = pd.DataFrame(error_df3)
它是不可复制的,我在一开始也定义了rng

注意:想象一个For循环For 1:nrow(dataframe)对于它通过多个模型的每个1,我已经在For循环的开头定义了rng和Seed

帮帮我

2个样本输出,这应该是理想的。这里的键指的是n_估计量

[在此处输入图像描述][模拟1]
[在此处输入图像描述][模拟2]

请找到答案:

错误:我使用的是
rng=Randomstate实例[np.random.Randomstate(1962)]

理想情况下,我应该在random_state变量中将种子值提到int

i、 e
rng=1962
为随机实例设定种子


然后我们应该继续使用模型中的随机状态变量进行再现。

您忘记附加图像了。另外,如果你能提供一个很长的代码就更好了,这就是为什么我没有添加任何相关的代码。我正在询问Algo以使其可复制,就像在其中使用随机_状态变量一样