def earnn( experiment="one_month_forecast", include_pred_month=True, surrounding_pixels=None, pretrained=True, ignore_vars=None, ): data_path = get_data_path() if not pretrained: predictor = EARecurrentNetwork( hidden_size=128, data_folder=data_path, experiment=experiment, include_pred_month=include_pred_month, surrounding_pixels=surrounding_pixels, ignore_vars=ignore_vars, ) predictor.train(num_epochs=50, early_stopping=5) predictor.evaluate(save_preds=True) predictor.save_model() else: predictor = load_model(data_path / f"models/{experiment}/ealstm/model.pt") test_file = data_path / f"features/{experiment}/test/2018_3" assert test_file.exists() all_explanations_for_file(test_file, predictor, batch_size=100)
def earnn( experiment="one_month_forecast", include_pred_month=True, surrounding_pixels=None, pretrained=True, ignore_vars=None, include_static=True, ): # if the working directory is alread ml_drought don't need ../data if Path(".").absolute().as_posix().split("/")[-1] == "ml_drought": data_path = Path("data") else: data_path = Path("../data") if not pretrained: predictor = EARecurrentNetwork( hidden_size=128, data_folder=data_path, experiment=experiment, include_pred_month=include_pred_month, surrounding_pixels=surrounding_pixels, ignore_vars=ignore_vars, include_static=include_static, ) predictor.train(num_epochs=50, early_stopping=10) predictor.evaluate(save_preds=True) predictor.save_model() else: predictor = load_model(data_path / f"models/{experiment}/ealstm/model.pt")
def earnn(experiment='one_month_forecast', include_pred_month=True, surrounding_pixels=None, pretrained=True): # if the working directory is alread ml_drought don't need ../data if Path('.').absolute().as_posix().split('/')[-1] == 'ml_drought': data_path = Path('data') else: data_path = Path('../data') if not pretrained: predictor = EARecurrentNetwork(hidden_size=128, data_folder=data_path, experiment=experiment, include_pred_month=include_pred_month, surrounding_pixels=surrounding_pixels) predictor.train(num_epochs=50, early_stopping=5) predictor.evaluate(save_preds=True) predictor.save_model() else: predictor = load_model(data_path / f'models/{experiment}/ealstm/model.pt') test_file = data_path / f'features/{experiment}/test/2018_3' assert test_file.exists() all_shap_for_file(test_file, predictor, batch_size=100)
def earnn( experiment="one_month_forecast", include_pred_month=True, surrounding_pixels=None, pretrained=False, explain=False, static="features", ignore_vars=None, num_epochs=50, early_stopping=5, static_embedding_size=10, hidden_size=128, predict_delta=False, spatial_mask=None, include_latlons=False, normalize_y=True, include_prev_y=True, include_yearly_aggs=True, # new clear_nans=True, weight_observations=False, pred_month_static=False, ): data_path = get_data_path() if not pretrained: predictor = EARecurrentNetwork( hidden_size=hidden_size, data_folder=data_path, experiment=experiment, include_pred_month=include_pred_month, surrounding_pixels=surrounding_pixels, static=static, static_embedding_size=static_embedding_size, ignore_vars=ignore_vars, predict_delta=predict_delta, spatial_mask=spatial_mask, include_latlons=include_latlons, normalize_y=normalize_y, include_prev_y=include_prev_y, include_yearly_aggs=include_yearly_aggs, clear_nans=clear_nans, weight_observations=weight_observations, pred_month_static=pred_month_static, ) predictor.train(num_epochs=num_epochs, early_stopping=early_stopping) predictor.evaluate(save_preds=True) predictor.save_model() else: predictor = load_model(data_path / f"models/{experiment}/ealstm/model.pt") if explain: test_file = data_path / f"features/{experiment}/test/2018_3" assert test_file.exists() all_explanations_for_file(test_file, predictor, batch_size=100)
static_ignore_vars=static_ignore_vars, target_var='discharge_spec', test_years=np.arange(2011, 2017), ) print("** Initialised Models! **") # test the training functionality ealstm.train( num_epochs=1, # 100 # early_stopping=10 ) # test the prediction functionality # test_arrays_dict, preds_dict = ealstm.predict() ealstm.evaluate( spatial_unit_name='station_id', save_preds=True ) results_dict = json.load(open('data/models/one_timestep_forecast/ealstm/results.json', 'rb')) print("Overall RMSE: ", results_dict['total']) # 1 epoch = 1.04 / 2.81 # 100 epochs = 0.72 / 2.04 # save the model ealstm.save_model() # load the model from src.models import load_model ealstm2 = load_model(Path('data/models/one_timestep_forecast/ealstm/model.pt')) # ------------------------------------------------------------------------