Exemple #1
0
SEED=1
param={'loss_function':'Logloss',
       'eval_metric' : 'AUC',
       'verbose': 200,      
       'random_seed':SEED}


param_rad={
            'learning_rate': [0.03,0.1],
        'depth': [4,5] ,
        'l2_leaf_reg': [1, 3, 5, 7, 9],
        'grow_policy':['SymmetricTree','Lossguide'],
        'bagging_temperature':[0.1,0.2,0.5,0.4,0.7,1]       }

model=CatBoostClassifier(task_type='GPU')
result=model.randomized_search(param_rad,X_n_train,y_n_train,cv=5)

cat = CatBoostClassifier(**param,grow_policy='Lossguide')

cat.fit(X_n_train,y_n_train,
        eval_set=(X_n_test,y_n_test),
        #cat_features =  categorical_features_indices,
        use_best_model=True,plot=True)

prediction = cat.predict_proba(Test,
                                ntree_start=0,
                                ntree_end=0,
                                thread_count=1,
                                verbose=None)[:,1]

Exemple #2
0
val_data = (X_test, y_test)
cat_f = [] # Categorical columns for catboost
for col in X.columns:
    if X[col].dtype == np.uint8:
        cat_f.append(col)
        

model = CatBoostClassifier()
model.fit(X_train, y_train, verbose=0, cat_features=cat_f)
validate(model, val_data)

model_tun = CatBoostClassifier()
grid = {'learning_rate': [0.03, 0.1],
        'depth': [4, 6, 10],
        'l2_leaf_reg': [1, 3, 5, 7, 9]}
model_tun.randomized_search(grid, X=X, y=y)
clear_output()

validate(model_tun, val_data)

#%%
from sklearn.metrics import classification_report, confusion_matrix
y_pred = model_tun.predict(X_test)
y_pred = np.rint(y_pred)

print(classification_report(y_test, y_pred))

cm = confusion_matrix(y_test, y_pred)

print(cm)
#%%