Spaces:
Sleeping
Sleeping
Upload 4 files
Browse files- logistic_model.pkl +3 -0
- requirements.txt +4 -0
- scaler.pkl +3 -0
- streamlit_app.py +34 -0
logistic_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:747725f56f1ade7b3b3ac2cfcc2e8857b146c5af39fdb6ad9e2930cbfce4141f
|
| 3 |
+
size 755
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
scikit-learn
|
| 3 |
+
numpy
|
| 4 |
+
pandas
|
scaler.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a208f078302339ed946721df51be778ae5ab093196f61dfb011ba9b95ec5756e
|
| 3 |
+
size 696
|
streamlit_app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import pickle
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
# Load model and scaler
|
| 6 |
+
with open("logistic_model.pkl", "rb") as f:
|
| 7 |
+
model = pickle.load(f)
|
| 8 |
+
|
| 9 |
+
with open("scaler.pkl", "rb") as f:
|
| 10 |
+
scaler = pickle.load(f)
|
| 11 |
+
|
| 12 |
+
st.title("🚢 Titanic Survival Prediction")
|
| 13 |
+
st.write("Enter passenger details to predict survival.")
|
| 14 |
+
|
| 15 |
+
# User input fields
|
| 16 |
+
pclass = st.selectbox("Passenger Class", [1, 2, 3])
|
| 17 |
+
sex = st.radio("Sex", ["Male", "Female"])
|
| 18 |
+
age = st.slider("Age", 1, 100, 30)
|
| 19 |
+
fare = st.number_input("Fare", min_value=0.0, step=0.1)
|
| 20 |
+
embarked = st.selectbox("Embarked Port", ["Cherbourg (C)", "Queenstown (Q)", "Southampton (S)"])
|
| 21 |
+
|
| 22 |
+
# Convert categorical inputs
|
| 23 |
+
sex = 0 if sex == "Male" else 1
|
| 24 |
+
embarked = {"Cherbourg (C)": 0, "Queenstown (Q)": 1, "Southampton (S)": 2}[embarked]
|
| 25 |
+
|
| 26 |
+
# Normalize input
|
| 27 |
+
input_data = np.array([[pclass, sex, age, fare, embarked]])
|
| 28 |
+
input_data = scaler.transform(input_data) # Apply same scaling as training
|
| 29 |
+
|
| 30 |
+
# Prediction
|
| 31 |
+
if st.button("Predict"):
|
| 32 |
+
prediction = model.predict(input_data)[0]
|
| 33 |
+
outcome = "Survived 🟢" if prediction == 1 else "Did not survive 🔴"
|
| 34 |
+
st.write(f"**Prediction:** {outcome}")
|