我正在使用 Scikit Learn 构建一个随机森林分类器。
我的问题在于一个 4 类分类任务,值分布如下(在将我的数据以 80%-20% 的比例分成训练集和测试集之后):
y_train values
cautious_turn 386 # label and number of elements
aggressive_brake 356
cautious_brake 245
aggressive_turn 204
y_test values
cautious_turn 104
aggressive_brake 90
aggressive_turn 53
cautious_brake 51
完整的数据集包含 1489 个样本。训练集由 1191 个样本组成。
我正在尝试使用RandomizedSearchCVfrom优化我的随机森林超参数sklearn。
我的代码如下(只是一个例子):
from sklearn.model_selection import RandomizedSearchCV
import numpy as np
from pprint import pprint
# Number of trees in random forest
n_estimators = [int(x) for x in np.linspace(start = 1, stop = 150, num = 15)]
# Number of features to consider at every split
max_features = ['auto', 'sqrt']
# Maximum number of levels in tree
max_depth = [int(x) for x in np.linspace(10, 110, num = 11)]
max_depth.append(None)
# Minimum number of samples required to split a node
min_samples_split = [2, 5, 10]
# Minimum number of samples required at each leaf node
min_samples_leaf = [1, 2, 4]
# Method of selecting samples for training each tree
bootstrap = [True, False]
# Create the random grid
random_grid = {'n_estimators': n_estimators,
'max_features': max_features,
'max_depth': max_depth,
'min_samples_split': min_samples_split,
'min_samples_leaf': min_samples_leaf,
'bootstrap': bootstrap}
到目前为止,我的代码运行良好,没有任何问题。
我的问题是: 有没有任何方法/经验方法来决定哪个可能是我的超参数值的良好初始空间?
现在我只是从教程中复制了这些值。有什么方法可以决定哪些可能是(例如)用于min_samples_split查看我的数据的一个很好的值范围?是否有任何方法可以让我减少“探索”空间?
例如:我决定搜索min_samples_leaf = [1, 2, 4]而不是min_samples_leaf = [10, 15, 20]因为....(可能的动机在这里)