Skip to content

Instantly share code, notes, and snippets.

@brunowdev
Created June 7, 2020 19:56
Show Gist options
  • Save brunowdev/2b6312d90fa915506b4e3f7e15eb831a to your computer and use it in GitHub Desktop.
Save brunowdev/2b6312d90fa915506b4e3f7e15eb831a to your computer and use it in GitHub Desktop.
import pandas as pd
def show_results_and_save(model_pipeline, predictions):
df_results = predictions.select(['canceled', 'prediction']).toPandas()
df_results['prediction'] = df_results.prediction.apply(int)
# Display the results
_metrics = plot_metrics(df_results['canceled'], df_results['prediction'])
# Save the results
_model = model_pipeline.bestModel.stages[-1]
_model_name = _model.__class__.__name__
_model_info = {
'model_name' : _model_name,
'hyperparameters' : list(zip(list(map(lambda _param: _param.name, list(_model.extractParamMap()))), list(_model.extractParamMap().values())))
}
_metrics.update(_model_info)
_df_metrics = pd.DataFrame([_metrics])
_df_metrics.to_csv(f'spark_{_model_name}.csv', index = False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment