+from configparser import ConfigParser
+from math import sqrt
+from sklearn.metrics import mean_squared_error, mean_absolute_error
+from sklearn.model_selection import train_test_split
+
+import xgboost
+
+class Learning:
+
+ def __init__(self, config_file = None,
+ X = None, y = None):
+ self._config = ConfigParser()
+ self._config.read(config_file)
+
+ df = X
+ df['cible'] = y
+
+ print(df.head())
+
+ train_val_set, test_set = train_test_split(df, test_size = 0.2, random_state = 42)
+ train_set, val_set = train_test_split(train_val_set, test_size = 0.2, random_state = 42)
+
+ X_test = test_set.drop('cible', axis = 1)
+ y_test = test_set['cible'].copy()
+
+ X_train = train_set.drop('cible', axis=1)
+ y_train = train_set['cible'].copy()
+ X_val = val_set.drop('cible', axis=1)
+ y_val = val_set['cible'].copy()
+
+
+ if self._config['MODEL']['method'] == 'xgboost':
+ xgb_reg = xgboost.XGBRegressor(learning_rate = 0.01,
+ max_depth = 10,
+ random_state=42,
+ n_estimators = 173,
+ n_jobs=-1,
+ objective = 'count:poisson')
+
+ xgb_reg.fit(X_train, y_train,
+ eval_set=[(X_val, y_val)],
+ early_stopping_rounds=10)
+
+ y_test_pred = xgb_reg.predict(X_test)
+ print(sqrt(mean_squared_error(y_test_pred, y_test)), mean_absolute_error(y_test_pred,y_test))
\ No newline at end of file