Python 每次运行RandomForestRegressor时都会得到不同的结果
我使用此代码希望实现决定论:Python 每次运行RandomForestRegressor时都会得到不同的结果,python,numpy,scikit-learn,random-forest,non-deterministic,Python,Numpy,Scikit Learn,Random Forest,Non Deterministic,我使用此代码希望实现决定论: from sklearn.ensemble import RandomForestRegressor np.random.seed(0) import random random.seed(0) rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4) 但我的结果并不确定。这是为什么?我如何解决它?使用随机森林回归器中的随机状态参数: from sklea
from sklearn.ensemble import RandomForestRegressor
np.random.seed(0)
import random
random.seed(0)
rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4)
但我的结果并不确定。这是为什么?我如何解决它?使用
随机森林回归器中的随机状态参数:
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4,
random_state= 0)
每次都应返回相同的结果。
Scikit学习不使用其自身的全局随机状态;每当 RandomState实例或整数随机种子未作为 参数,它依赖于numpy全局随机状态,该状态可以设置 使用numpy.random.seed
也就是说,在导入之前添加
np.random.seed()
随机森林回归器也应该这样做。
来源:使用
随机森林回归器中的random\u state
参数:
from sklearn.ensemble import RandomForestRegressor
rf = RandomForestRegressor(n_estimators=1000, criterion='mse', min_samples_leaf=4,
random_state= 0)
每次都应返回相同的结果。
Scikit学习不使用其自身的全局随机状态;每当 RandomState实例或整数随机种子未作为 参数,它依赖于numpy全局随机状态,该状态可以设置 使用numpy.random.seed
也就是说,在导入之前添加
np.random.seed()
随机森林回归器也应该这样做。
来源:您需要将
random\u state
添加到回归模型中。您可能希望在RFRegressionor调用中使用random\u state参数。您应该添加np.random.seed()
在导入RandomForestRegressionor之前,请在脚本的顶部。@Baron查看我的答案并告诉我们您需要将Randomy\u state
添加到回归模型中您可能希望在RFRegressionor调用中使用Randomy\u state参数。您应该添加np.random.seed()
在导入RandomForestRegressionor之前,请在脚本顶部。@Baron查看我的答案,并告诉我们