Kaggle competition: Riiid Answer Correctness Prediction
dt = DecisionTreeClassifier(random_state = 12345)
 parameters_dt = {'criterion': ['gini', 'entropy'],
'max_depth':range(1, 100, 1),
'min_samples_leaf': range(1, 20),
'max_features':range(1, X_train.shape[1]+1)}
search_dt = RandomizedSearchCV(dt, parameters_dt, cv=5, scoring = 'accuracy', n_jobs = -1, random_state = 12345)
 search_dt.fit(X_train, y_train)
 best_dt = search_dt.best_estimator_
acc_dt = cross_val_score(best_dt, X_valid, y_valid, scoring = 'accuracy', cv = 10, n_jobs = -1)
 auc_dt = cross_val_score(best_dt, X_valid, y_valid, scoring = 'roc_auc', cv = 10, n_jobs = -1)
 print('AUC-ROC for Decision Tree on validation dataset:', sum(auc_dt)/len(auc_dt))
print('Accuracy for Decision Tree on validation dataset:', sum(acc_dt)/len(acc_dt))<compute_test_metric>
import torch
import pandas as pd
from saintmodel import SaintModel, SaintLightningModule, SaintHistory
from saintsubmit import load_saint_config, SaintPredictor, make_submission
confusion_m(best_dt, 'Confusion matrix for Logistic Regression')
 feature_importance(best_dt.feature_importances_, 'Feature importance for Decision Tree' )<train_on_grid>
args = load_saint_config()
model = SaintModel(
 seq_len=args.seq_len, n_dim=args.n_dim, std=args.std, dropout=args.dropout, nhead=args.nhead, n_layers=args.n_layers 
)
 module = SaintLightningModule(args, model )
rf = RandomForestClassifier(random_state = 12345)
 parameters_rf = {'n_estimators': range(1, 1800, 25),
'criterion': ['gini', 'entropy'],
'max_depth':range(1, 100),
'min_samples_split': range(1, 12),
'min_samples_leaf': range(1, 12),
'max_features':['auto', 'log2', 'sqrt', 'None']}
search_rf = RandomizedSearchCV(rf, parameters_rf, cv=5, scoring = 'accuracy', n_jobs = -1, random_state = 12345)
 search_rf.fit(X_train, y_train)
 best_rf = search_rf.best_estimator_
predict_rf = best_rf.predict(X_valid)
 auc_rf = cross_val_score(best_rf, X_valid, y_valid, scoring = 'roc_auc', cv = 10, n_jobs = -1)
 acc_rf = cross_val_score(best_rf, X_valid, y_valid, scoring = 'accuracy', cv = 10, n_jobs = -1)
 print('AUC-ROC for Random Forest on validation dataset:', sum(auc_rf)/len(auc_rf))
print('Accuracy for Random Forest on validation dataset:', sum(acc_rf)/len(acc_rf))<compute_test_metric>
%%time
module.load_state_dict(torch.load('/kaggle/input/riiid-saintp-solution/saint.ckpt')['state_dict'] )
confusion_m(best_rf, 'Confusion matrix for Random Forest')
 feature_importance(best_rf.feature_importances_, 'Feature importance for Random Forest' )<choose_model_class>
%%time
last_history = pd.read_pickle('/kaggle/input/riiid-saintp-solution/last_history.pickle')
 last_timestamp = pd.read_pickle('/kaggle/input/riiid-saintp-solution/last_timestamp.pickle')
 last_user_count = pd.read_pickle('/kaggle/input/riiid-saintp-solution/last_user_count.pickle')
 dict_lag = pd.read_pickle('/kaggle/input/riiid-saintp-solution/dict_lag.pickle')
 dict_elapsed = pd.read_pickle('/kaggle/input/riiid-saintp-solution/dict_elapsed.pickle')
 dict_user_count = pd.read_pickle('/kaggle/input/riiid-saintp-solution/dict_user_count.pickle' )
xgb = XGBClassifier(random_state = 12345, eval_metric='auc')
 parameters_xgb = {'eta': [0.01, 0.05, 0.1, 0.001, 0.005, 0.04, 0.2, 0.0001],
'min_child_weight':range(1, 5),
'max_depth':range(1, 6),
'learning_rate': [0.01, 0.05, 0.1, 0.001, 0.005, 0.04, 0.2],
'n_estimators':range(0, 2001, 50)}
search_xgb = RandomizedSearchCV(xgb, parameters_xgb, cv = 5, scoring = 'accuracy', n_jobs = -1, random_state = 12345)
 search_xgb.fit(X_train, y_train)
 best_xgb = search_xgb.best_estimator_
predict_xgb = best_xgb.predict(X_valid)
 auc_xgb = cross_val_score(best_xgb, X_valid, y_valid, scoring = 'roc_auc', cv = 10, n_jobs = -1)
 acc_xgb = cross_val_score(best_xgb, X_valid, y_valid, scoring = 'accuracy', cv = 10, n_jobs = -1)
 print('AUC-ROC for XGBoost on validation dataset:', sum(auc_xgb)/len(auc_xgb))
print('Accuracy for XGBoost on validation dataset:', sum(acc_xgb)/len(acc_xgb))<compute_test_metric>
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
 module.to(device )
confusion_m(best_xgb, 'Confusion matrix for XGBoost')
 feature_importance(best_xgb.feature_importances_, 'Feature importance for XGBoost' )<compute_train_metric>
saint_history = SaintHistory(
 args, last_history, last_timestamp, last_user_count,
dict_lag, dict_user_count, dict_elapsed 
)
 predictor = SaintPredictor(module.model, saint_history )
cb = CatBoostClassifier(random_state = 12345, iterations = 300, eval_metric='Accuracy', verbose = 100)
 parameters_cb = {'depth': range(6, 11),
'learning_rate': [0.001, 0.01, 0.05, 0.1, 0.0001]}
search_cb = RandomizedSearchCV(cb, parameters_cb, cv = 5, scoring = 'accuracy', n_jobs = -1, random_state = 12345)
 search_cb.fit(X_train, y_train, verbose = 100)
 best_cb = search_cb.best_estimator_
predict_cb = best_cb.predict(X_valid)
 auc_cb = cross_val_score(best_cb, X_valid, y_valid, scoring = 'roc_auc', cv = 10, n_jobs = -1)
 acc_cb = cross_val_score(best_cb, X_valid, y_valid, scoring = 'accuracy', cv = 10, n_jobs = -1)
 print('AUC-ROC for CatBoost on validation dataset:', sum(auc_cb)/len(auc_cb))
print('Accuracy for CatBoost on validation dataset:', sum(acc_cb)/len(acc_cb))<compute_test_metric>
env = riiideducation.make_env()
<train_on_grid><EOS> 
make_submission(env, predictor )