倍数模型的GridSearchCV



我想使用GridSearchCV运行不同的模型。

models = {
"RandomForestRegressor": RandomForestRegressor(),
"AdaBoostRegressor": AdaBoostRegressor(),}
params = {
"RandomForestRegressor": {"n_estimators": [10, 50, 75], "max_depth": [10, 20, 50], "max_features": ["auto","sqrt","log2"]},
"AdaBoostRegressor": {"n_estimators": [50, 100],"learning_rate": [0.01,0.1, 0.5],"loss": ["linear","square"]},}

我希望这会有所帮助,但也许只是在您的"create_ mode";作用例如,这里有一个非常基本的create_model函数,它使用激活函数作为参数,作为GridsearchCV试图帮助您调整的参数。

def create_model(activation_fn):
# create model
model = Sequential()
model.add(Dense(30, input_dim=feats, activation=activation_fn,
kernel_initializer='normal'))
model.add(Dropout(0.2))
model.add(Dense(10, activation=activation_fn))
model.add(Dropout(0.2))
model.add(Dense(1, activation='linear'))
# Compile model
model.compile(loss='mean_squared_error',
optimizer='adam',
metrics=['mean_squared_error','mae'])
return model

现在,您可以修改它,使其具有第二个名为model_type的参数(或您想称之为的任何参数(。

def create_model(model_type = 'rfr'):
if model_type == 'rfr':
......
elif model_type == 'xgb':
.......
elif model_type == 'neural_network':
.......

然后,在输入到您调用的GridsearchCV中的params字典中,只需为model_type键提供一个要调整(优化(的模型列表。只需确保在给定的";如果";语句,将其放入适当的代码中以创建所需的模型。

最新更新