Guest User

Untitled

a guest
Sep 20th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. def trn_validate(df, trn_end, val_end, layer_sizes):
  2. df_train = split_at(df, end_date=trn_end)
  3. df_val = split_at(df, start_date=trn_end, end_date=val_end)
  4.  
  5. numeric_features_train, scaling_mean, scaling_std = scale(df_train)
  6. numeric_features_val, _, _ = scale(df_val, scaling_mean, scaling_std)
  7. nan_trn = numeric_features_train.isnull()
  8. nan_val = numeric_features_val.isnull()
  9. imputer = build_imputer(numeric_features_train)
  10.  
  11. trn_imputed = apply_imputer(imputer, numeric_features_train)
  12. val_imputed = apply_imputer(imputer, numeric_features_val)
  13.  
  14. trn_imputed = pd.concat((trn_imputed, nan_trn.astype(float)), 1)
  15. val_imputed = pd.concat((val_imputed, nan_val.astype(float)), 1)
  16.  
  17. trn_sold, trn_Y = build_Y(df_train, trn_end)
  18.  
  19. val_sold, val_Y = build_Y(df_val, dataset_end)
  20.  
  21. n_features = trn_imputed.shape[1]
  22.  
  23. model = Model(n_features, layer_sizes=layer_sizes)
  24. yhat = model.train(
  25. trn_imputed.values,
  26. val_imputed.values,
  27. trn_Y.values,
  28. val_Y.values,
  29. trn_sold.values,
  30. val_sold.values,
  31. epochs=10)
  32. model.visualize(
  33. 'Loss and r2_scores ' + str(trn_end)[:10] + ' to \n' +
  34. str(val_end)[:10] + ' layers: ' + str(layer_sizes),
  35. str(trn_end)[:7] + ':' + str(val_end)[:7])
  36. return model.val_losses[-1], yhat, val_Y
Add Comment
Please, Sign In to add comment