Sek*_*har 5 machine-learning data-science catboost
我正在研究一个数据科学回归问题,训练集上约有 90,000 行,测试集上有 8500 行。有 9 个分类列,无缺失数据。对于这种情况,我应用了一个 catboostregressor,它给了我相当好的 R2(98.51)和 MAE(3.77)。其他节点LGBM、XGBOOST在catboost下执行。
现在我想增加 R2 值并减少 MAE 以获得更准确的结果。需求也是如此。
我通过添加不同值的 'loss_function': ['MAE'], 'l2_leaf_reg':[3], 'random_strength': [4], 'bagging_Temperature':[0.5] 进行了多次调整,但性能是相同的。
谁能帮助我如何通过最小化 MAE 和 MSE 来提高 R2 值?
Ada*_*ase 12
简单的方法——
您可以使用 Scikit-LearnGridSearchCV来查找最适合您的CatBoostRegressor模型的超参数。您可以传递一个超参数字典,并将GridSearchCV循环遍历所有超参数并告诉您哪些参数最好。你可以这样使用它 -
from sklearn.model_selection import GridSearchCV
model = CatBoostRegressor()
parameters = {'depth' : [6,8,10],
'learning_rate' : [0.01, 0.05, 0.1],
'iterations' : [30, 50, 100]
}
grid = GridSearchCV(estimator=model, param_grid = parameters, cv = 2, n_jobs=-1)
grid.fit(X_train, y_train)
Run Code Online (Sandbox Code Playgroud)
另一种方法 -
如今,模型很复杂并且有很多参数需要调整。人们正在使用贝叶斯优化技术(例如 Optuna)来调整超参数。CatBoostClassifier您可以使用 Optuna 进行如下调整:
!pip install optuna
import catboost
import optuna
def objective(trial):
X_train, X_val, y_train, y_val = train_test_split(X, y, test_size = 0.2)
param = {
"objective": trial.suggest_categorical("objective", ["Logloss", "CrossEntropy"]),
'learning_rate' : trial.suggest_loguniform('learning_rate', 0.001, 0.3),
"colsample_bylevel": trial.suggest_float("colsample_bylevel", 0.01, 0.1),
"max_depth": trial.suggest_int("max_depth", 1, 15),
"boosting_type": trial.suggest_categorical("boosting_type", ["Ordered", "Plain"]),
"bootstrap_type": trial.suggest_categorical(
"bootstrap_type", ["Bayesian", "Bernoulli", "MVS"]),
}
if param["bootstrap_type"] == "Bayesian":
param["bagging_temperature"] = trial.suggest_float("bagging_temperature", 0, 10)
elif param["bootstrap_type"] == "Bernoulli":
param["subsample"] = trial.suggest_uniform("subsample", 0.1, 1)
gbm = catboost.CatBoostClassifier(**param, iterations = 10000)
gbm.fit(X_train, y_train, eval_set = [(X_val, y_val)], verbose = 0, early_stopping_rounds = 100)
preds = gbm.predict(X_val)
pred_labels = np.rint(preds)
accuracy = accuracy_score(y_val, pred_labels)
return accuracy
study = optuna.create_study(direction = "maximize")
study.optimize(objective, n_trials = 200, show_progress_bar = True)
Run Code Online (Sandbox Code Playgroud)
此方法需要很长时间(可能需要 1-2 小时)。当您有很多参数需要调整时,最好使用此方法。否则,请使用网格搜索 CV。
| 归档时间: |
|
| 查看次数: |
10064 次 |
| 最近记录: |