【发布时间】:2020-09-18 13:16:51
【问题描述】:
Python:3.6
窗口:10
我对随机森林和手头的问题几乎没有疑问:
我正在使用 Gridsearch 来运行使用随机森林的回归问题。我想绘制与 gridsearch 发现的最佳拟合参数对应的树。这是代码。
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=55)
# Use the random grid to search for best hyperparameters
# First create the base model to tune
rf = RandomForestRegressor()
# Random search of parameters, using 3 fold cross validation,
# search across 100 different combinations, and use all available cores
rf_random = RandomizedSearchCV(estimator = rf, param_distributions = random_grid, n_iter = 50, cv = 5, verbose=2, random_state=56, n_jobs = -1)
# Fit the random search model
rf_random.fit(X_train, y_train)
rf_random.best_params_
最好的参数是:
{'n_estimators': 1000,
'min_samples_split': 5,
'min_samples_leaf': 1,
'max_features': 'auto',
'max_depth': 5,
'bootstrap': True}
如何使用上述参数绘制这棵树?
我的因变量
y位于 [0,1] 范围内(连续),并且所有预测变量都是二元或分类变量。一般来说,哪种算法可以很好地适应这个输入和输出特征空间。我试过随机森林。 (没有给出那么好的结果)。注意这里y变量是一种比率,因此它在0和1之间。Example: Expense on food/Total Expense上述数据有偏差,这意味着依赖变量或
y变量在 60% 的数据中具有 value=1,在其余数据中介于 0 和 1 之间。比如0.66, 0.87等等。因为我的数据只有二进制
{0,1}和分类变量{A,B,C}。我需要将其转换为one-hot encoding变量以使用随机森林吗?
【问题讨论】:
标签: python-3.x machine-learning scikit-learn random-forest