Kaggle competition: Riiid Answer Correctness Prediction
<SOS> metric: AUC Kaggle data source: riiid-answer-correctness-prediction<prepare_x_and_y>
import optuna
from sklearn.feature_selection import RFECV
from lightgbm import LGBMClassifier
import pandas as pd
import joblib
import numpy as np
import riiideducation
from sklearn.metrics import roc_auc_score
from sklearn.model_selection import train_test_split
import optuna.integration.lightgbm as lgb
from optuna.samplers import TPESampler
import matplotlib.pyplot as plt
x_train = train.drop(labels=["label"], axis=1)
 x_train = x_train / 255.0
x_train = x_train.values.reshape(-1, 28, 28, 1)
 y_train = train["label"]
y_train = np.array(to_categorical(y_train, num_classes=10))
x_test = test / 255.0
x_test = x_test.values.reshape(-1, 28, 28, 1)
 print(x_train.shape, y_train.shape, x_test.shape )<train_model>
questions_df = pd.read_csv(
 '.. /input/riiid-test-answer-prediction/questions.csv',
usecols=[0, 3],
dtype={'question_id': 'int16', 'part': 'int8'} 
)
 model = joblib.load('.. /input/lgb-model-2/Final_lgb_2.joblib')
 selector = joblib.load('.. /input/selector-2/Selector_2.joblib')
 user_answers_df = pd.read_csv('.. /input/preprocessingcontentuser/user.csv')
 content_answers_df = pd.read_csv('.. /input/preprocessingcontentuser/content.csv' )
( x_train_mnist, y_train_mnist),(x_val_mnist, y_val_mnist)= mnist.load_data()
x_train_mnist = np.concatenate(( x_train_mnist, x_val_mnist))
y_train_mnist = np.concatenate(( y_train_mnist, y_val_mnist))
x_train_mnist = x_train_mnist.reshape(( x_train_mnist.shape[0], 28, 28, 1))
X_train_mnist = x_train_mnist / 255
y_train_mnist = np.array(to_categorical(y_train_mnist.reshape(( y_train_mnist.shape[0], 1)) ,num_classes=10))
print(x_train_mnist.shape, y_train_mnist.shape )<concatenate>
features = [
'timestamp',
'user_id',
'content_id',
'prior_question_elapsed_time',
'prior_question_had_explanation',
'part',
'mean_user_accuracy',
'questions_skew',
'questions_std',
'questions_var',
'questions_sem',
'content_mean',
'content_skew',
'content_std',
'content_var',
'content_sem'
]
features = [features[i] for i in range(len(selector.support_)) if selector.support_[i] == True]
x_train = np.concatenate(( x_train, x_train_mnist))
y_train = np.concatenate(( y_train, y_train_mnist))<choose_model_class>
env = riiideducation.make_env()
iter_test = env.iter_test()
<define_variables><EOS> 
for(test_df, sample_prediction_df)in iter_test:
test_df = pd.merge(test_df, questions_df, left_on='content_id', right_on='question_id', how='left')
 test_df.drop(columns=['question_id'], inplace=True)
 test_df['prior_question_had_explanation'].fillna(bool(True), inplace=True)
 test_df = test_df.replace([-np.inf, np.inf], np.nan)
 test_df = test_df.fillna(test_df.mean())
 test_df = test_df[test_df['content_type_id'] != 1]
test_df = test_df.merge(user_answers_df, how='left', on='user_id')
 test_df = test_df.merge(content_answers_df, how='left', on='content_id')
 test_df['prior_question_had_explanation'] = test_df['prior_question_had_explanation'].astype(bool)
 test_df = test_df.replace([-np.inf, np.inf], np.nan)
 test_df = test_df.fillna(test_df.mean())
 test_df['answered_correctly'] = model.predict_proba(test_df[features])[:,1]
env.predict(test_df.loc[test_df['content_type_id'] == 0, ['row_id', 'answered_correctly']])