File size: 2,803 Bytes
e4fd44c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import streamlit as st 
import pandas as pd 
import numpy as np 
import sklearn
from sklearn.model_selection import train_test_split
from sklearn.svm import SVR
from sklearn.metrics import mean_absolute_error

st.header(" :blue[Estimated Time Arrival Predictor] :car:")  
st.subheader("This tool helps to predict the estimated time arrival based on the weather,hour,traffic and week conditions from the starting point to the destination based upon longitude and latitude")
df = pd.read_csv("hyderabad_eta_data.csv")

# Sliders in the middle of the page
start_lat = st.slider(
    "Select Latitude",
    min_value=-90.0,
    max_value=90.0,
    value=0.0,
    step=0.1
)

start_lon = st.slider(
    "Select start Longitude",
    min_value=-180.0,
    max_value=180.0,
    value=0.0,
    step=0.1
)


end_lat = st.slider(
    "Select end  Latitude",
    min_value=-90.0,
    max_value=90.0,
    value=0.0,
    step=0.1
)


end_lon = st.slider(
    "Select end Longitude",
    min_value=-180.0,
    max_value=180.0,
    value=0.0,
    step=0.1
)





distance = st.slider(
    "Select the distance (km)",
    min_value = 0.0,
    max_value = 700.0,
    value = 100.0,
    step =1.0
)


traffic = st.selectbox("Select the traffic density", [1,  2, 3, 4, 5, 6, 7, 8, 9, 10])


weather = st.selectbox("Select the weather condition", ["rainy","clear","foggy"])

week_day = st.selectbox("Select the week",["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"])
week_val = {"Sunday" : 0,"Monday" : 1,"Tuesday" : 2,"Wednesday": 3,"Thursday": 4,"Friday": 5,"Saturday" : 6}
week = week_val[week_day]



hour = st.slider(
    "select the hour",
    min_value = 0,
    max_value = 23,
    value = 0,
    step = 1
)


# Map user-selected weather condition
weather_map = {'rainy': 0, 'clear': 1, 'foggy': 2}
weather_val = weather_map[weather]

# Prepare dataset
df["weather_condition"] = df["weather_condition"].map(weather_map)
X = df.drop("ETA", axis=1)
y = df["ETA"]

# splitting the target variable 
X = df.drop("ETA", axis =1)
y = df["ETA"]

# doing the train-test split
X_train, X_test,y_train,y_test = train_test_split(X,y , test_size= 0.2, random_state=23)

# Model Building and Model Evaluation 
sv_r = SVR(kernel='rbf', C=100, epsilon=0.1)
sv_r.fit(X_train,y_train)

y_pred = sv_r.predict(X_test)
result = mean_absolute_error(y_pred,y_test)

features = np.array([[start_lat, start_lon,end_lat,end_lon,distance,weather_val,traffic,week,hour]])

estimated_arrival = sv_r.predict(features)[0]

# Display formatted output without array brackets
if st.button(" :red[Click to predict estimated time]"):
    st.header(" :orange[The ESTIMATED TIME ARRIVAL IS ]")
    st.markdown(f"<h2 style='color:brown; font-size:36px;'><strong>{estimated_arrival:.2f} hours</strong></h2>", unsafe_allow_html=True)