Chuẩn bị cho hồi quy Rừng ngẫu nhiên

Feature Engineering với PySpark

John Hogue

Lead Data Scientist, General Mills

Giả định cần cho đặc trưng

Hồi quy Rừng ngẫu nhiên

  • Dữ liệu lệch/không chuẩn? OK
  • Chưa chuẩn hóa? OK
  • Thiếu dữ liệu? OK
  • Dữ liệu phân loại? OK

Giả định

Feature Engineering với PySpark

Đặc trưng bổ sung

Kinh tế

  • Lãi suất thế chấp 30 năm

Chính phủ

  • Giá nhà trung vị theo thành phố
  • Tỷ lệ độ tuổi nhà theo thành phố
  • Tỷ lệ kích thước nhà theo thành phố

Xã hội

  • Điểm đi bộ
  • Điểm đi xe đạp

Theo mùa

  • Ngày nghỉ ngân hàng
Feature Engineering với PySpark

Đặc trưng được thiết kế

Đặc trưng thời gian

  • Ít giá trị với dữ liệu một năm
  • Tuần có ngày lễ

Tỷ lệ, suất, tổng

  • Ngữ cảnh kinh doanh
  • Ngữ cảnh cá nhân

Đặc trưng mở rộng

  • Cột văn bản không tự do
  • Cần loại bỏ quan sát ít
# What is shape of our data?
print((df.count(), len(df.columns)))
(5000, 126)
Feature Engineering với PySpark

Chuyển cột DataFrame thành vector đặc trưng

from pyspark.ml.feature import VectorAssembler
# Replace Missing values
df = df.fillna(-1)
# Define the columns to be converted to vectors
features_cols = list(df.columns)
# Remove the dependent variable from the list
features_cols.remove('SALESCLOSEPRICE')
Feature Engineering với PySpark

Chuyển cột DataFrame thành vector đặc trưng

# Create the vector assembler transformer
vec = VectorAssembler(inputCols=features_cols, outputCol='features')

# Apply the vector transformer to data df = vec.transform(df)
# Select only the feature vectors and the dependent variable ml_ready_df = df.select(['SALESCLOSEPRICE', 'features'])
# Inspect Results 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
Feature Engineering với PySpark

Giờ đã sẵn sàng cho máy học!

Feature Engineering với PySpark

Preparing Video For Download...