X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/predictops.git/blobdiff_plain/83fdad7cdd97734f036d464acceebaf3b0f0a44b..7ee7381044cbe0539ec18052a77b9f6600678bb9:/predictops/learn/learning.py?ds=inline diff --git a/predictops/learn/learning.py b/predictops/learn/learning.py index 959271d..f13c3a6 100644 --- a/predictops/learn/learning.py +++ b/predictops/learn/learning.py @@ -10,6 +10,7 @@ from statistics import mean, stdev import lightgbm as lgb import matplotlib import os +import pandas as pd import pylab as P import xgboost @@ -25,8 +26,12 @@ class Learning: self._config.read(config_file) self._file_name = file_name logger.info("Dealing with the horizon of prediction") - self._X = X[:-horizon] - self._y = y[horizon:] + if horizon: + self._X = X[:-horizon] + self._y = y[horizon:] + else: + self._X = X + self._y = y self._learn() self._evaluate() @@ -83,11 +88,12 @@ class Learning: for k in range(10): txt += f"Percentage of errors lower than {k}: {[abs(int(u-v))<=k for u,v in zip(self._y_test.values, y_test_pred)].count(True)/len(self._y_test)*100}\n" - print(txt) rep = (Path.cwd() / self._file_name) rep.mkdir() - filename = str(self._file_name / os.path.basename(self._file_name)) - with open(filename + ".result", 'w') as f: + self._filename = str(self._file_name / os.path.basename(self._file_name)) + + print(txt) + with open(self._filename + ".result", 'w') as f: f.write(txt) y_true = self._df[self._df.year == self._df.year.max()].cible @@ -101,7 +107,7 @@ class Learning: P.xlabel('Hour in the year') P.ylabel('Number of cumulated interventions') P.legend() - P.savefig(filename + ".png") + P.savefig(self._filename + ".png") yy_test_pred = self._reg.predict(self._X_test) P.figure(figsize=(36, 16)) @@ -111,10 +117,10 @@ class Learning: P.xlabel('Hour in the year') P.ylabel('Number of cumulated interventions') P.legend() - P.savefig(filename + "-test.png") + P.savefig(self._filename + "-test.png") if self._config['MODEL']['method'] == 'xgboost': xgboost.plot_importance(self._reg) fig = matplotlib.pyplot.gcf() fig.set_size_inches(15, 130) - fig.savefig(filename + '-feat_importance.pdf') + fig.savefig(self._filename + '-feat_importance.pdf')