모델 해석, 저장 및 로드

PySpark로 하는 Feature Engineering

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로 하는 Feature Engineering

모델 해석

# 결과 해석
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로 하는 Feature Engineering

모델 저장 및 로드

# 모델 저장
model.save('rfr_real_estate_model')
from pyspark.ml.regression import RandomForestRegressionModel

# 모델 불러오기
model2 = RandomForestRegressionModel.load('rfr_real_estate_model')
PySpark로 하는 Feature Engineering

마지막 연습으로 넘어가겠습니다!

PySpark로 하는 Feature Engineering

Preparing Video For Download...