Preparando para Random Forest Regression

Feature Engineering com PySpark

John Hogue

Lead Data Scientist, General Mills

Premissas necessárias para os recursos

Random Forest Regression

  • Dados enviesados/não normais? OK
  • Sem escala? OK
  • Dados ausentes? OK
  • Dados categóricos? OK

Premissas

Feature Engineering com PySpark

Recursos anexados

Econômicos

  • Taxas de hipoteca de 30 anos

Governamentais

  • Preço mediano de imóveis na cidade
  • Percentuais por idade dos imóveis na cidade
  • Percentuais por tamanho dos imóveis na cidade

Sociais

  • Walk Score
  • Bike Score

Sazonais

  • Feriados bancários
Feature Engineering com PySpark

Recursos criados

Recursos temporais

  • Valor limitado com 1 ano de dados
  • Semanas com feriados

Taxas, razões, somas

  • Contexto de negócio
  • Contexto pessoal

Recursos expandidos

  • Colunas de texto não livre
  • Precisam remover poucas observações
# What is shape of our data?
print((df.count(), len(df.columns)))
(5000, 126)
Feature Engineering com PySpark

Colunas do dataframe para vetores de recursos

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 com PySpark

Colunas do dataframe para vetores de recursos

# 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 com PySpark

Agora estamos prontos para machine learning!

Feature Engineering com PySpark

Preparing Video For Download...