def _load_data(self): # データ未読み込みの場合 if self._is_data_loaded == False: # 気象データを読み込み loader = GsmLoader(self._base_dir, self._temp_dir, self._input_dir, self._input2_dir, self._gsm_thinout_interval, self._weather_convert_mode) df = loader.load() # 浮動小数点を32ビットに変更する df = util.type_to_float32(df) # NaNを置換する if type(self._model) is ModelDnn: # DNNの場合は平均値で置換する df = util.fill_na_avg(df) elif type(self._model) is ModelRandomForest: # ランダムフォレストの場合は-9999で置換する df = df.fillna(-9999) elif type(self._model) is ModelXgboost: # XGBoostの場合はNaNのままで問題無し pass # 学習データ・テスト用データ作成 self._train_x, self._train_y, self._test_x, self._test_y = \ self._make_training_data(df, self._label_name) # ラベル数をモデルに渡す self._label_num = self._train_y.nunique() self._model.add_param('label_num', self._label_num) self._is_data_loaded = True
def _preprocess_ground_weather(self, ground_df): # 9時と21時のデータを抽出する ground_df = util.extract_row_isin(ground_df, '時', [9, 21]) # 天気記号を数値に変換する ground_df = wdfproc.convert_symbol_to_number(ground_df) # 地上気象データから不要データを除去する ground_df = wdfproc.drop_unneeded_ground(ground_df) # 風速・風向きを数値に変換する ground_df = wdfproc.convert_wind_to_vector_ground(ground_df) # 天気を数値に変換する ground_df = wdfproc.convert_weather_to_interger(ground_df) # 雲量を浮動小数点数に変換する ground_df = wdfproc.convert_cloud_volume_to_float(ground_df) # 天気を指定した境界値で分類する # - 水戸は3分割、それ以外は○分割にする label_name = 'Mito_天気' weather_cols = [col for col in ground_df.columns if('天気' in col)] weather_cols.pop( weather_cols.index(label_name) ) ground_df = wdfproc.replace_weather( ground_df, columns=weather_cols, mode=wdfproc.WeatherConvertMode.Coarse) ground_df = wdfproc.replace_weather(ground_df, columns=[label_name]) # 浮動小数点数を32ビットに変換する ground_df = util.type_to_float32(ground_df) # 不要な列を除去する ground_df = wdfproc.drop_columns( ground_df, [ '現地気圧', '露点温度', '蒸気圧', '日照時間', '降雪', '積雪', '視程', '全天日射' ] #[ '現地気圧', '海面気圧', '気温', '露点温度', '蒸気圧', '日照時間', # '降雪', '積雪', '雲量', '視程', '全天日射', '降水量', '風速' ] #[ '現地気圧', '海面気圧', '気温', '露点温度', '蒸気圧', '日照時間', # '降雪', '積雪', '雲量', '視程', '全天日射', '降水量' ] #[ '現地気圧', '海面気圧', '気温', '露点温度', '蒸気圧', '日照時間', # '降雪', '積雪', '視程', '全天日射' ] ) print(ground_df.info()) return ground_df
def _preprocess_highrise_weather(self, highrise_df): # 高層気象データから不要データを除去する #highrise_df = wdfproc.drop_unneeded_higirise(highrise_df) # 風速・風向きを数値に変換する highrise_df = wdfproc.convert_wind_to_vector_highrise(highrise_df) # 浮動小数点数を32ビットに変換する highrise_df = util.type_to_float32(highrise_df) # 不要な列を除去する highrise_df = wdfproc.drop_columns( highrise_df, #[ '地上', '1000', '925', '900', '850', '800', '700', '600', '400', '350', '300'] ['1000', '925', '900', '800', '600', '400', '350', '300']) print(highrise_df.info()) return highrise_df
def _preprocess_ground_weather(self, ground_df): # 9時と21時のデータを抽出する ground_df = util.extract_row_isin(ground_df, '時', [9, 21]) # 天気記号を数値に変換する ground_df = wdfproc.convert_symbol_to_number(ground_df) # 地上気象データから不要データを除去する ground_df = wdfproc.drop_unneeded_ground(ground_df) # 風速・風向きを数値に変換する ground_df = wdfproc.convert_wind_to_vector_ground(ground_df) # 天気を数値に変換する ground_df = wdfproc.convert_weather_to_interger(ground_df) # 雲量を浮動小数点数に変換する ground_df = wdfproc.convert_cloud_volume_to_float(ground_df) # 天気を晴れ,くもり,雨のいずれかに分類する weather_cols = [col for col in ground_df.columns if ('天気' in col)] ground_df = wdfproc.replace_weather( ground_df, columns=weather_cols, mode=wdfproc.WeatherConvertMode.Coarse) # 浮動小数点数を32ビットに変換する ground_df = util.type_to_float32(ground_df) # 不要な列を除去する ground_df = wdfproc.drop_columns( ground_df, #[ '現地気圧', '海面気圧', '降水量', '気温', '露点温度', '蒸気圧', '湿度', '風速', # '日照時間', '全天日射', '降雪', '積雪', '視程', ] ['現地気圧', '露点温度', '蒸気圧', '日照時間', '降雪', '積雪', '視程', '全天日射']) print(ground_df.info()) return ground_df