Eine Kaggle-Competition in Python gewinnen
Yauhen Babakhin
Kaggle Grandmaster


# Daten lesen
taxi_train = pd.read_csv('taxi_train.csv')
taxi_test = pd.read_csv('taxi_test.csv')
from sklearn.model_selection import train_test_split
# Lokale Validierung erstellen
validation_train, validation_test = train_test_split(taxi_train,
test_size=0.3,
random_state=123)
import numpy as np # Allen Testbeobachtungen den mittleren Fahrpreis zuweisen taxi_test['fare_amount'] = np.mean(taxi_train.fare_amount)# Vorhersagen in Datei schreiben taxi_test[['id','fare_amount']].to_csv('mean_sub.csv', index=False)
| Validierungs-RMSE | Public-LB-RMSE | Public-LB-Platz |
|---|---|---|
| 9.986 | 9.409 | 1449 / 1500 |
# Mittleren Fahrpreis je Gruppe berechnen
naive_prediction_groups = taxi_train.groupby('passenger_count').fare_amount.mean()
# Vorhersagen für den Testsatz erstellen taxi_test['fare_amount'] = taxi_test.passenger_count.map(naive_prediction_groups)# Vorhersagen in Datei schreiben taxi_test[['id','fare_amount']].to_csv('mean_group_sub.csv', index=False)
| Validierungs-RMSE | Public-LB-RMSE | Public-LB-Platz |
|---|---|---|
| 9.978 | 9.407 | 1411 / 1500 |
# Nur numerische Features wählen
features = ['pickup_longitude', 'pickup_latitude',
'dropoff_longitude', 'dropoff_latitude', 'passenger_count']
from sklearn.ensemble import GradientBoostingRegressor # Gradient-Boosting-Modell trainieren gb = GradientBoostingRegressor() gb.fit(taxi_train[features], taxi_train.fare_amount)# Vorhersagen für Testdaten erstellen taxi_test['fare_amount'] = gb.predict(taxi_test[features])
# Vorhersagen in Datei schreiben
taxi_test[['id','fare_amount']].to_csv('gb_sub.csv', index=False)
| Validierungs-RMSE | Public-LB-RMSE | Public-LB-Platz |
|---|---|---|
| 5.996 | 4.595 | 1109 / 1500 |
| Modell | Validierungs-RMSE | Public-LB-RMSE |
|---|---|---|
| Einfacher Mittelwert | 9.986 | 9.409 |
| Gruppen-Mittelwert | 9.978 | 9.407 |
| Gradient Boosting | 5.996 | 4.595 |
| Modell | Validierungs-RMSE | Public-LB-RMSE |
|---|---|---|
| Modell A | 3.500 | 3.800 |
| Modell B | 3.300 | 4.100 |
| Modell C | 3.200 | 3.900 |
| Modell | Validierungs-RMSE | Public-LB-RMSE |
|---|---|---|
| Modell A | 3.400 | 3.900 |
| Modell B | 3.100 | 3.400 |
| Modell C | 2.900 | 3.300 |
Eine Kaggle-Competition in Python gewinnen