Kaggle competition: INGV - Volcanic Eruption Prediction
scale_age_fare = preprocessing.StandardScaler().fit(combined_train_test[['Age', 'Fare']])
 combined_train_test[['Age', 'Fare']] = scale_age_fare.transform(combined_train_test[['Age', 'Fare']] )<drop_column>
train = pd.read_csv('.. /input/ingv-tsfresh-7730/train.csv', sep = ';')
 train.set_index('Unnamed: 0', inplace = True)
 test = pd.read_csv('.. /input/ingv-tsfresh-7730/test.csv', sep = ';')
 test.set_index('Unnamed: 0', inplace = True )
combined_train_test.drop(['Name', 'PassengerId', 'Embarked', 'Sex', 'Title', 'Fare_Category', 'Family_Size_Category', 'Age_Category', 'First_Name', 'Last_Name', 'Original_Name', 'Name_Length_Category'], axis = 1, inplace = True )<prepare_x_and_y>
train_data = combined_train_test[:891]
test_data = combined_train_test[891:]
titanic_train_data_X = train_data.drop(['Survived'], axis = 1)
 titanic_train_data_y = train_data['Survived']
titanic_test_data_X = test_data.drop(['Survived'], axis = 1 )<choose_model_class>
%%time
Y = train['time_to_eruption']
X = train.drop(['time_to_eruption'], axis = 1)
 X_test = test
n_fold = 5
cv = KFold(n_splits=n_fold, shuffle=True, random_state=42)
 oof = np.zeros(len(X))
cat_prediction = np.zeros(len(X_test))
mae, r2 = [], []
PARAMS = {
'random_seed': 42,
'eval_metric': 'MAE',
'task_type': 'GPU',
}
for fold_n,(train_index, valid_index)in enumerate(cv.split(X)) :
print('
Fold', fold_n, 'started at', ctime())
 X_train = X.iloc[train_index,:]
X_valid = X.iloc[valid_index,:]
Y_train = Y.iloc[train_index]
Y_valid = Y.iloc[valid_index]
best_model = CatBoostRegressor(**PARAMS, thread_count = -1)
 train_dataset = Pool(data=X_train,
label=Y_train, 
)
 eval_dataset = Pool(data=X_valid,
label=Y_valid, 
)
 best_model.fit(train_dataset,
use_best_model=True,
verbose = False,
plot = True,
eval_set=eval_dataset,
early_stopping_rounds=100)
 y_pred = best_model.predict(Pool(data=X_valid))
mae.append(mean_absolute_error(Y_valid, y_pred))
r2.append(r2_score(Y_valid, y_pred))
print('MAE: ', mean_absolute_error(Y_valid, y_pred))
print('R2: ', r2_score(Y_valid, y_pred))
cat_prediction += best_model.predict(Pool(data=X_test))
cat_prediction /= n_fold
print('='*45)
 print('CV mean MAE: {0:.4f}, std: {1:.4f}.'.format(np.mean(mae), np.std(mae)))
 print('CV mean R2: {0:.4f}, std: {1:.4f}.'.format(np.mean(r2), np.std(r2)) )
<choose_model_class><EOS> 
submission = pd.DataFrame()
submission['segment_id'] = test.index
submission['time_to_eruption'] = cat_prediction
submission.to_csv('submission.csv', header=True, index=False )