PySpark로 하는 Feature Engineering
John Hogue
Lead Data Scientist, General Mills
랜덤 포레스트 회귀

경제
정부
사회
계절성
시간 특징
비율·비중·합계
확장된 특징
# 데이터 형태는?
print((df.count(), len(df.columns)))
(5000, 126)
from pyspark.ml.feature import VectorAssembler
# 결측값 대체
df = df.fillna(-1)
# 벡터로 변환할 열 정의
features_cols = list(df.columns)
# 종속 변수를 목록에서 제거
features_cols.remove('SALESCLOSEPRICE')
# 벡터 어셈블러 변환기 생성 vec = VectorAssembler(inputCols=features_cols, outputCol='features')# 벡터 변환기를 데이터에 적용 df = vec.transform(df)# 특징 벡터와 종속 변수만 선택 ml_ready_df = df.select(['SALESCLOSEPRICE', 'features'])# 결과 확인 ml_ready_df.show(5)
+----------------+--------------------+
| SALESCLOSEPRICE| features|
+----------------+--------------------+
|143000 |(125,[0,1,2,3,5,6...|
|190000 |(125,[0,1,2,3,5,6...|
|225000 |(125,[0,1,2,3,5,6...|
|265000 |(125,[0,1,2,3,4,5...|
|249900 |(125,[0,1,2,3,4,5...|
+----------------+--------------------+
only showing top 5 rows
PySpark로 하는 Feature Engineering