Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def trn_validate(df, trn_end, val_end, layer_sizes):
- df_train = split_at(df, end_date=trn_end)
- df_val = split_at(df, start_date=trn_end, end_date=val_end)
- numeric_features_train, scaling_mean, scaling_std = scale(df_train)
- numeric_features_val, _, _ = scale(df_val, scaling_mean, scaling_std)
- nan_trn = numeric_features_train.isnull()
- nan_val = numeric_features_val.isnull()
- imputer = build_imputer(numeric_features_train)
- trn_imputed = apply_imputer(imputer, numeric_features_train)
- val_imputed = apply_imputer(imputer, numeric_features_val)
- trn_imputed = pd.concat((trn_imputed, nan_trn.astype(float)), 1)
- val_imputed = pd.concat((val_imputed, nan_val.astype(float)), 1)
- trn_sold, trn_Y = build_Y(df_train, trn_end)
- val_sold, val_Y = build_Y(df_val, dataset_end)
- n_features = trn_imputed.shape[1]
- model = Model(n_features, layer_sizes=layer_sizes)
- yhat = model.train(
- trn_imputed.values,
- val_imputed.values,
- trn_Y.values,
- val_Y.values,
- trn_sold.values,
- val_sold.values,
- epochs=10)
- model.visualize(
- 'Loss and r2_scores ' + str(trn_end)[:10] + ' to \n' +
- str(val_end)[:10] + ' layers: ' + str(layer_sizes),
- str(trn_end)[:7] + ':' + str(val_end)[:7])
- return model.val_losses[-1], yhat, val_Y
Add Comment
Please, Sign In to add comment