Upload 4 files
Browse files- 06-final-pipeline-notebook-newyork.ipynb +0 -0
- app.py +97 -0
- nyc_lgb_best_model.pkl +3 -0
- requirements.txt +9 -0
06-final-pipeline-notebook-newyork.ipynb
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
app.py
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
# Modeli yükle
|
| 7 |
+
model = joblib.load("final_lgb_nyc.pkl") # senin final modeli
|
| 8 |
+
|
| 9 |
+
# Örnek lokasyon listesi (mahalle/sokak)
|
| 10 |
+
locations = [
|
| 11 |
+
"Manhattan", "Brooklyn", "Queens", "Bronx", "Staten Island"
|
| 12 |
+
]
|
| 13 |
+
|
| 14 |
+
# Örnek hava durumu seçenekleri
|
| 15 |
+
weather_options = ["Clear", "Rain", "Snow", "Fog", "Cloudy"]
|
| 16 |
+
|
| 17 |
+
def predict_trip_duration(
|
| 18 |
+
pickup_location, dropoff_location, pickup_hour, pickup_dayofweek,
|
| 19 |
+
pickup_month, weather, passenger_count
|
| 20 |
+
):
|
| 21 |
+
# Basit feature engineering
|
| 22 |
+
vendor_id = 1 # sabit varsayım
|
| 23 |
+
store_and_fwd_flag = 0 # sabit varsayım
|
| 24 |
+
|
| 25 |
+
# Örnek koordinat ataması (gerçek uygulamada bir lookup tablosu gerekir)
|
| 26 |
+
loc_coords = {
|
| 27 |
+
"Manhattan": (40.7580, -73.9855),
|
| 28 |
+
"Brooklyn": (40.6782, -73.9442),
|
| 29 |
+
"Queens": (40.7282, -73.7949),
|
| 30 |
+
"Bronx": (40.8448, -73.8648),
|
| 31 |
+
"Staten Island": (40.5795, -74.1502)
|
| 32 |
+
}
|
| 33 |
+
|
| 34 |
+
pickup_lat, pickup_lon = loc_coords[pickup_location]
|
| 35 |
+
dropoff_lat, dropoff_lon = loc_coords[dropoff_location]
|
| 36 |
+
|
| 37 |
+
# Mesafe feature’leri
|
| 38 |
+
manhattan_distance = abs(pickup_lon - dropoff_lon) + abs(pickup_lat - dropoff_lat)
|
| 39 |
+
euclidean_distance = np.sqrt((pickup_lon - dropoff_lon)**2 + (pickup_lat - dropoff_lat)**2)
|
| 40 |
+
longitude_diff = abs(pickup_lon - dropoff_lon)
|
| 41 |
+
latitude_diff = abs(pickup_lat - dropoff_lat)
|
| 42 |
+
|
| 43 |
+
speed_estimate = 0 # placeholder
|
| 44 |
+
passenger_per_distance = passenger_count / (manhattan_distance + 0.001)
|
| 45 |
+
|
| 46 |
+
# Categorical encode
|
| 47 |
+
is_weekend = int(pickup_dayofweek in [5,6])
|
| 48 |
+
|
| 49 |
+
weather_mapping = {w:i for i,w in enumerate(weather_options)}
|
| 50 |
+
weather_encoded = weather_mapping.get(weather, 0)
|
| 51 |
+
|
| 52 |
+
df = pd.DataFrame({
|
| 53 |
+
"pickup_hour": [pickup_hour],
|
| 54 |
+
"pickup_dayofweek": [pickup_dayofweek],
|
| 55 |
+
"pickup_month": [pickup_month],
|
| 56 |
+
"manhattan_distance": [manhattan_distance],
|
| 57 |
+
"euclidean_distance": [euclidean_distance],
|
| 58 |
+
"longitude_diff": [longitude_diff],
|
| 59 |
+
"latitude_diff": [latitude_diff],
|
| 60 |
+
"speed_estimate": [speed_estimate],
|
| 61 |
+
"passenger_per_distance": [passenger_per_distance],
|
| 62 |
+
"vendor_id": [vendor_id],
|
| 63 |
+
"store_and_fwd_flag": [store_and_fwd_flag],
|
| 64 |
+
"is_weekend": [is_weekend],
|
| 65 |
+
"weather": [weather_encoded]
|
| 66 |
+
})
|
| 67 |
+
|
| 68 |
+
# Tahmin (log-transform modeli ise expm1 uygulanabilir)
|
| 69 |
+
pred_log = model.predict(df)
|
| 70 |
+
pred = np.expm1(pred_log) if np.min(pred_log) > 0 else pred_log
|
| 71 |
+
pred = max(pred[0], 0) # negatif tahminleri 0 yap
|
| 72 |
+
|
| 73 |
+
return f"{pred:.2f} saniye (~{pred/60:.1f} dakika)"
|
| 74 |
+
|
| 75 |
+
# --- Arayüz inputları ---
|
| 76 |
+
inputs = [
|
| 77 |
+
gr.Dropdown(label="Pickup Location", choices=locations, value="Manhattan"),
|
| 78 |
+
gr.Dropdown(label="Dropoff Location", choices=locations, value="Brooklyn"),
|
| 79 |
+
gr.Slider(label="Pickup Hour", minimum=0, maximum=23, step=1, value=9),
|
| 80 |
+
gr.Slider(label="Pickup Day of Week (0=Mon)", minimum=0, maximum=6, step=1, value=1),
|
| 81 |
+
gr.Slider(label="Pickup Month", minimum=1, maximum=12, step=1, value=6),
|
| 82 |
+
gr.Dropdown(label="Weather", choices=weather_options, value="Clear"),
|
| 83 |
+
gr.Slider(label="Passenger Count", minimum=1, maximum=6, step=1, value=1)
|
| 84 |
+
]
|
| 85 |
+
|
| 86 |
+
# --- Output ---
|
| 87 |
+
outputs = gr.Textbox(label="Tahmini Trip Duration")
|
| 88 |
+
|
| 89 |
+
iface = gr.Interface(
|
| 90 |
+
fn=predict_trip_duration,
|
| 91 |
+
inputs=inputs,
|
| 92 |
+
outputs=outputs,
|
| 93 |
+
title="NYC Taxi Trip Duration Predictor",
|
| 94 |
+
description="Kullanıcının girdiği lokasyon, saat ve hava durumuna göre tahmini yolculuk süresini verir."
|
| 95 |
+
)
|
| 96 |
+
|
| 97 |
+
iface.launch()
|
nyc_lgb_best_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7c405620739062cc3162a18b12c88a1fbcf2058db4c630e065b3b3b397d655d6
|
| 3 |
+
size 7171742
|
requirements.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
pandas
|
| 2 |
+
numpy
|
| 3 |
+
lightgbm
|
| 4 |
+
xgboost
|
| 5 |
+
joblib
|
| 6 |
+
shap
|
| 7 |
+
scikit-learn
|
| 8 |
+
matplotlib
|
| 9 |
+
gradio
|