Download app.py from CshardZ/app-test: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/CshardZ/app-test/resolve/main/app.py
- Command line
-
hf download hf://spaces/CshardZ/app-test/app.py
-
curl -L -o app.py https://huggingface.co/spaces/CshardZ/app-test/resolve/main/app.py
1.55 kB
| import numpy as np | |
| import pandas as pd | |
| from sklearn.model_selection import train_test_split | |
| from sklearn.preprocessing import StandardScaler | |
| import streamlit as st | |
| from src.model import LogisticRegression | |
| st.title("Customer Chrun Classifier") | |
| st.divider() | |
| file_path = r"telco_customer_churn.csv" | |
| # 1. Load CSV | |
| df = pd.read_csv(file_path) | |
| df["TotalCharges"] = pd.to_numeric(df["TotalCharges"], errors="coerce") | |
| df = df.dropna() | |
| df["target"] = (df["Churn"] == "Yes").astype(int) | |
| # 2. Feature selection UI | |
| numeric_cols = ["tenure", "MonthlyCharges", "TotalCharges", "SeniorCitizen"] | |
| selected = st.multiselect( | |
| "Select Numeric Features:", options=numeric_cols, default=numeric_cols | |
| ) | |
| if selected: | |
| X = df[selected].values | |
| y = df["target"].values | |
| X_train, X_test, y_train, y_test = train_test_split( | |
| X, y, test_size=0.2, random_state=42 | |
| ) | |
| scaler = StandardScaler() | |
| X_train_scaled = scaler.fit_transform(X_train) | |
| X_test_scaled = scaler.transform(X_test) | |
| # 3. Train using YOUR class | |
| m, n = X_train_scaled.shape | |
| model = LogisticRegression(X_train_scaled, y_train, m, n) | |
| model.gradient_descent(alpha=0.1, epochs=500) | |
| # 4. Predict | |
| probs = model.predict(X_test_scaled) | |
| preds = (probs >= 0.5).astype(int) | |
| acc = np.mean(preds == y_test) | |
| # 5. Display | |
| st.metric("Model Test Accuracy", f"{acc * 100:.2f}%") | |
| st.write( | |
| "**Learned Weights:**", | |
| pd.DataFrame({"Feature": selected, "Weight": model.w}), | |
| ) |