Views
No views yet
1import joblib
2from huggingface_hub import hf_hub_download
3import pandas as pd
4
5repo_id = "Waleed74/traffic-prediction-pk"
6
7# Download model & encoder
8model_path = hf_hub_download(repo_id=repo_id, filename="traffic_classifier.pkl")
9encoder_path = hf_hub_download(repo_id=repo_id, filename="target_encoder.pkl")
10
11# Load them
12model = joblib.load(model_path)
13target_encoder = joblib.load(encoder_path)
14
15feature_names = model.feature_names_in_
16print("Feature names:", feature_names)
17
18# Example input row
19row = [
20 18, # Time
21 2, # Day of the week
22 320, # CarCount
23 150, # BikeCount
24 20, # BusCount
25 10, # TruckCount
26 500, # Total
27 0 # Traffic Situation
28]
29
30df = pd.DataFrame([row], columns=feature_names)
31
32prediction = model.predict(df)
33predicted_label = target_encoder.inverse_transform(prediction)[0]
34
35print("Predicted Traffic Status:", predicted_label)