Interpretare, salvare e caricare i modelli

Feature Engineering con PySpark

John Hogue

Lead Data Scientist, General Mills

Interpretare un modello

import pandas as pd
# Converti le feature importances in una colonna pandas
fi_df = pd.DataFrame(model.featureImportances.toArray(), 
                     columns=['importance'])
# Converti l'elenco dei nomi delle feature in una colonna pandas
fi_df['feature'] = pd.Series(feature_cols)
# Ordina i dati per importanza della feature
fi_df.sort_values(by=['importance'], ascending=False, inplace=True)
Feature Engineering con PySpark

Interpretare un modello

# Interpreta i risultati
model_df.head(9)
|          feature        |importance|
|-------------------------|----------|
| LISTPRICE               | 0.312101 |
| ORIGINALLISTPRICE       | 0.202142 |
| LIVINGAREA              | 0.124239 |
| SQFT_TOTAL              | 0.081260 |
| LISTING_TO_MEDIAN_RATIO | 0.075086 |
| TAXES                   | 0.048452 |
| SQFTABOVEGROUND         | 0.045859 |
| BATHSTOTAL              | 0.034397 |
| LISTING_PRICE_PER_SQFT  | 0.018253 |
Feature Engineering con PySpark

Salvare e caricare i modelli

# Salva il modello
model.save('rfr_real_estate_model')
from pyspark.ml.regression import RandomForestRegressionModel

# Carica il modello da
model2 = RandomForestRegressionModel.load('rfr_real_estate_model')
Feature Engineering con PySpark

Ultimo set di esercizi!

Feature Engineering con PySpark

Preparing Video For Download...