Bir Model Oluşturma

PySpark ile Özellik Mühendisliği

John Hogue

Lead Data Scientist, General Mills

RandomForestRegressor

Temel Model Parametreleri

  • featuresCol="features"
  • labelCol="label"
  • predictionCol="prediction"
  • seed=None

Modelimizdeki Parametre Değerleri

  • featuresCol="features"
  • labelCol="SALESCLOSEPRICE"
  • predictionCol="Prediction_Price"
  • seed=42
PySpark ile Özellik Mühendisliği

Bir Random Forest Eğitme

from pyspark.ml.regression import RandomForestRegressor
# Kullanılacak sütunlarla modeli başlat
rf = RandomForestRegressor(featuresCol="features",
                           labelCol="SALESCLOSEPRICE",
                           predictionCol="Prediction_Price",
                           seed=42
                           )
# Modeli eğit
model = rf.fit(train_df)
PySpark ile Özellik Mühendisliği

Bir Modelle Tahmin

# Tahmin yap
predictions = model.transform(test_df)
# Sonuçları incele
predictions.select("Prediction_Price", "SALESCLOSEPRICE").show(5)
+------------------+---------------+
|  Prediction_Price|SALESCLOSEPRICE|
+------------------+---------------+
|426029.55463222397|         415000|
| 708510.8806005502|         842500|
| 164275.7116183204|         161000|
| 208943.4143642175|         200000|
|217152.43272221283|         205000|
+------------------+---------------+
only showing top 5 rows
PySpark ile Özellik Mühendisliği

Bir Modeli Değerlendirme

from pyspark.ml.evaluation import RegressionEvaluator
# Test hatasını hesaplamak için sütunları seç
evaluator = RegressionEvaluator(labelCol="SALESCLOSEPRICE", 
                                predictionCol="Prediction_Price")
# Değerlendirme metriklerini oluştur
rmse = evaluator.evaluate(predictions, {evaluator.metricName: "rmse"})
r2 = evaluator.evaluate(predictions, {evaluator.metricName: "r2"})
# Model metriklerini yazdır
print('RMSE: ' + str(rmse))
print('R^2: ' + str(r2))
RMSE: 22898.84041072095
R^2: 0.9666594402208077
PySpark ile Özellik Mühendisliği

Hadi biraz veri modelleyelim!

PySpark ile Özellik Mühendisliği

Preparing Video For Download...