Esempio n. 1
0
    def draw_predictions(self,
                         corp_name,
                         scaler_close,
                         data_params,
                         test_predict,
                         invest_predicts=None):
        """예측 그래프를 그린다."""
        dir = 'predicts'
        dir_chart = os.path.join(self.main.DIR_CHARTS, dir)
        DataUtils.create_dir(dir_chart)

        if invest_predicts is not None and test_predict is not None:
            predicts = np.append(test_predict, invest_predicts)
            #print(len(test_predict), len(invest_predicts))
        elif test_predict is not None:
            predicts = test_predict
        else:
            predicts = invest_predicts
        dataY = np.append(data_params.testY, data_params.investY)

        preds = []
        for pred in predicts:
            #print(pred, scaler_close)
            preds.append(DataUtils.inverse_scaled_data(scaler_close, pred))

        close_values = []
        for y in dataY:
            close_values.append(DataUtils.inverse_scaled_data(scaler_close, y))

        df_data = self.get_predicts_data(data_params, close_values, preds)
        df_data['date'] = pd.to_datetime(df_data['date'], format='%Y.%m.%d')
        df_data_index = df_data.set_index('date')
        self.draw_predictions_seaborn(df_data_index, dir, corp_name)
        self.save_csv(df_data, dir, corp_name)
Esempio n. 2
0
    def draw_rmses(self, train_rmse, test_rmse, corp_name):
        """RMSE 그래프를 그린다."""
        dir = 'trains'
        dir_chart = os.path.join(self.main.DIR_CHARTS, dir)
        DataUtils.create_dir(dir_chart)
        rmse_data = {'train': train_rmse, 'test': test_rmse}
        #print(len(train_rmse), len(test_rmse))
        df_rmses = pd.DataFrame.from_dict(rmse_data)

        self.draw_rmse_seaborn(df_rmses, dir, corp_name)
        self.save_csv(df_rmses, dir, corp_name)
Esempio n. 3
0
 def get_session_dir(self,
                     corp_code: str,
                     is_reinforcement: bool = False,
                     name: str = 'main') -> str:
     """저장할 세션의 디렉토리"""
     file_name = self.get_session_filename(corp_code)
     if is_reinforcement:
         dir = os.path.join(self.SESSIONS_DIR, 'reinforcement', name,
                            self.params.train_model, file_name)
     else:
         dir = os.path.join(self.SESSIONS_DIR, self.params.train_model,
                            file_name)
     DataUtils.create_dir(dir)
     return dir
Esempio n. 4
0
    def get_file_path(self, dir:str, corp_name:str, extension:str, start:str=None, end:str=None)->str:
        """저장할 파일 경로 """
        if start is None:
            invest_start_date = self.params.invest_start_date
        else:
            invest_start_date = start

        if end is None:
            invest_end_date = self.params.invest_end_date
        else:
            invest_end_date = end

        if dir == 'invests_total':
            dir = os.path.join(self.main.DIR_CHARTS, dir)
        else:
            dir = os.path.join(self.main.DIR_CHARTS, dir, corp_name)

        DataUtils.create_dir(dir)
        corp_name = corp_name.replace(" ", "")
        return os.path.join(dir, corp_name + "_" + invest_start_date + "-" + invest_end_date  + "." + extension)