!pip install shap==0.39.0
!pip install streamlit==1.13.0
#load in libraries
import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pyplot as plt
from joblib import dump, load
import streamlit as st
Run to view results
import pandas as pd
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier
import streamlit as st
import os
from joblib import dump, load
# Load your trained model
model = load(os.path.join(os.getcwd(), 'DecisionTree_MatchPrediction.joblib'))
# Load the dataset
try:
dataset_path = os.path.join(os.getcwd(), 'speeddating.csv')
st.write(f"Loading dataset from: {dataset_path}")
df = pd.read_csv(dataset_path)
st.write("Dataset loaded successfully")
except Exception as e:
st.error(f"Failed to load dataset: {e}")
df = None
# Ensure df is loaded before using it
if df is not None:
# Define your target value (y) and your features (df_un)
y = 'match'
df_dt = df.drop(columns=[y]) # Exclude the target value
# Optional: Exclude any other columns if necessary
# For example, exclude 'age' or any other feature if needed
# df_dt = df_dt.loc[:, df_dt.columns != 'age']
# Streamlit interface
st.title('Speeddating Match Prediction')
st.write('Predict whether there will be a match based on your inputs.')
# Collecting user input
age = st.sidebar.slider('Your Age', min_value=18, max_value=70, value=25)
like = st.sidebar.slider('Like Score', min_value=0, max_value=10, value=5)
decision = st.sidebar.selectbox('Your Decision', ['Yes', 'No'])
# Map inputs to the corresponding feature values
input_data = {
'age': age,
'like': like,
'decision': 1 if decision == 'Yes' else 0
}
# Convert the input data to a DataFrame
input_df = pd.DataFrame([input_data])
# Handle missing columns that may have been excluded in df_dt
input_df = input_df.reindex(columns=df_dt.columns, fill_value=0)
# Make prediction
if st.sidebar.button('Predict'):
prediction = model.predict(input_df)[0]
st.write(f"The model predicts a {'match' if prediction == 1 else 'no match'}.")
else:
st.error("The dataset could not be loaded. Please check the file path and the dataset format.")
Run to view results
!streamlit run speeddating_app.py --server.port 8080
Run to view results
Run to view results