Spaces:
Sleeping
Sleeping
File size: 2,709 Bytes
2523f9f def2609 2523f9f def2609 3f616a4 2523f9f def2609 2523f9f def2609 2523f9f def2609 2523f9f def2609 2523f9f | 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 | import streamlit as st
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import tensorflow as tf
from tensorflow import keras
from keras.metrics import Precision, Recall
import numpy as np
# Load dataset directly from file path
df = pd.read_csv(r"Assessment - Form Responses.csv")
# Streamlit config
st.set_page_config(page_title=" Match Prediction Using Personality and Lifestyle Data", layout="centered")
st.title("Match Prediction Using Personality and Lifestyle Data")
# Drop unwanted columns
if "Timestamp" in df.columns and "Email Address" in df.columns:
df.drop(columns=["Timestamp", "Email Address"], inplace=True)
# Show data
st.subheader("๐ Raw Data")
st.write(df.head())
# Save original for UI
original_df = df.copy()
# Label Encoding
encoders = {}
for col in df.columns:
le = LabelEncoder()
df[col] = le.fit_transform(df[col])
encoders[col] = le
# Features and labels (last column = label)
x = df.iloc[:, :-1]
y = df.iloc[:, -1]
# Build ANN
model = keras.Sequential([
keras.layers.Input(shape=(x.shape[1],)),
keras.layers.Dense(8, kernel_initializer=keras.initializers.GlorotNormal(seed=42)),
keras.layers.PReLU(),
keras.layers.Dense(3, kernel_initializer=keras.initializers.GlorotNormal(seed=42),
kernel_regularizer=keras.regularizers.L2()),
keras.layers.PReLU(),
keras.layers.BatchNormalization(),
keras.layers.Dropout(0.2),
keras.layers.Dense(1, activation="sigmoid", kernel_initializer=keras.initializers.HeNormal(seed=42))
])
model.compile(loss="binary_crossentropy", optimizer="adam", metrics=["accuracy", Precision(), Recall()])
# Train model
if st.button("๐ Train Model"):
checkpoint_cb = keras.callbacks.ModelCheckpoint(
"best_model.h5", monitor="val_loss", save_best_only=True, mode="min"
)
with st.spinner("Training in progress..."):
history = model.fit(x, y, validation_split=0.2, batch_size=8, epochs=30,
callbacks=[checkpoint_cb], verbose=0)
st.success("โ
Model training completed!")
# Prediction section
st.subheader("๐ก Make a Prediction")
user_inputs = {}
for col in x.columns:
options = encoders[col].classes_
selected = st.selectbox(f"Select {col}:", options)
user_inputs[col] = encoders[col].transform([selected])[0]
if st.button("๐ฎ Predict Match"):
input_df = pd.DataFrame([user_inputs.values()], columns=user_inputs.keys())
prediction = model.predict(input_df)[0][0]
if prediction >= 0.5:
st.success(f"๐ It's a Match! (Confidence: {round(prediction * 100, 2)}%)")
else:
st.warning(f"๐ No Match. (Confidence: {round((1 - prediction) * 100, 2)}%)")
|