# -- Code Cell --
import pandas as pd
train = pd.read_csv('train.csv')
test = pd.read_csv('test.csv')

# -- Code Cell --
train.head()

# -- Code Cell --
train.head()

# -- Code Cell --
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import mean_absolute_error
from catboost import CatBoostRegressor

X = train.drop(columns=['medie', 'anomalie', 'id'])
y = train['medie']

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=42
)

cat_cols = X_train.select_dtypes(include=object).columns.tolist()
num_cols = [c for c in X_train.columns if c not in cat_cols]
scaler = StandardScaler()
X_train_sc = X_train.copy()
X_test_sc = X_test.copy()
X_train_sc[num_cols] = scaler.fit_transform(X_train[num_cols])
X_test_sc[num_cols] = scaler.transform(X_test[num_cols])
model = CatBoostRegressor(
    cat_features=cat_cols,
    random_state=42,
    verbose=0
)

model.fit(X_train_sc, y_train)
y_pred = model.predict(X_test_sc)

mae = mean_absolute_error(y_test, y_pred)
mae

# -- Code Cell --
task1 = 'MATEMATICA MATE-INFO'

# -- Code Cell --
task2 = 2022

# -- Code Cell --
X_pred = test.drop(columns = ['id'])
y_pred = model.predict(X_pred)
test['medie'] = y_pred

# -- Code Cell --
from sklearn.linear_model import LogisticRegression
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.metrics import roc_auc_score
from catboost import CatBoostClassifier
X2 = train.drop(columns=['medie', 'anomalie', 'id'])
y2 = train['medie']

X_train2, X_test2, y_train2, y_test2 = train_test_split(
    X, y, test_size=0.2, random_state=42
)

cat_cols = X_train2.select_dtypes(include=object).columns.tolist()
num_cols = [c for c in X_train2.columns if c not in cat_cols]
scaler2 = StandardScaler()
X_train2_sc = X_train.copy()
X_test2_sc = X_test.copy()
X_train2_sc[num_cols] = scaler2.fit_transform(X_train2[num_cols])
X_test2_sc[num_cols]  = scaler2.transform(X_test2[num_cols])
model2 = CatBoostClassifier(cat_features=cat_cols,random_state=42)
model2.fit(X_train2_sc, y_train2)
y_proba2 = model2.predict_proba(X_test2_sc)[:, 1]
auc2 = roc_auc_score(y_test2, y_proba2)
auc2