File size: 1,541 Bytes
aac92b5
f6850a7
 
 
aac92b5
 
 
f6850a7
aac92b5
 
f6850a7
 
 
 
 
 
 
 
aac92b5
 
f6850a7
aac92b5
 
f6850a7
 
aac92b5
 
 
 
 
f6850a7
aac92b5
 
 
f6850a7
aac92b5
 
f6850a7
aac92b5
 
 
 
f6850a7
aac92b5
 
 
f6850a7
aac92b5
 
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
# app.py

import streamlit as st
import pandas as pd
from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder

st.set_page_config(page_title="EV Range Classifier", layout="centered")
st.title("🔋 Ultra-Light EV Range Classifier")

@st.cache_data
def load_data():
    url = "https://drive.google.com/uc?export=download&id=1QBTnXxORRbJzE5Z2aqKHsVqgB7mqowiN"
    return pd.read_csv(url)

df = load_data()

# Simple cleaning & encoding
for col in df.select_dtypes(include="object"):
    df[col] = df[col].fillna(df[col].mode()[0])
    df[col] = LabelEncoder().fit_transform(df[col])
for col in df.select_dtypes(include="number"):
    df[col] = df[col].fillna(df[col].median())

# Prepare target & features
TARGET = "Electric Range"
if TARGET not in df.columns:
    st.error(f"Missing column: '{TARGET}'")
    st.stop()

df["Target"] = (df[TARGET] > df[TARGET].median()).astype(int)
num_cols = [c for c in df.select_dtypes(include="number") if c not in (TARGET, "Target")]
FEATURES = num_cols[:2]  # only first 2 numeric cols

X = df[FEATURES]
y = df["Target"]

# Train/test split & model
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
model = RandomForestClassifier(n_estimators=10, random_state=42)
model.fit(X_train, y_train)

# Display result
accuracy = model.score(X_test, y_test)
st.metric(label="Test Accuracy", value=f"{accuracy:.2f}")

if st.checkbox("Show features used"):
    st.write(FEATURES)