模型解读、保存与加载

使用 PySpark 进行特征工程

John Hogue

Lead Data Scientist, General Mills

解读模型

import pandas as pd
# 将特征重要性转换为 pandas 列
fi_df = pd.DataFrame(model.featureImportances.toArray(), 
                     columns=['importance'])
# 将特征名列表转换为 pandas 列
fi_df['feature'] = pd.Series(feature_cols)
# 按特征重要性排序
fi_df.sort_values(by=['importance'], ascending=False, inplace=True)
使用 PySpark 进行特征工程

解读模型

# 解读结果
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 |
使用 PySpark 进行特征工程

保存与加载模型

# 保存模型
model.save('rfr_real_estate_model')
from pyspark.ml.regression import RandomForestRegressionModel

# 加载模型
model2 = RandomForestRegressionModel.load('rfr_real_estate_model')
使用 PySpark 进行特征工程

进入最后一组练习!

使用 PySpark 进行特征工程

Preparing Video For Download...