|
import joblib |
|
import pandas as pd |
|
import streamlit as st |
|
|
|
|
|
|
|
scaler = joblib.load(r'scaler.pickle') |
|
|
|
|
|
classifier_lr = joblib.load(r'model_lr.pickle') |
|
|
|
|
|
classifier_dt = joblib.load(r'model_dt.pickle') |
|
|
|
|
|
|
|
html_temp = """ |
|
<div style ="background-color:black;padding:13px"> |
|
<h1 style ="color:white;text-align:center;">Titanic Survivors Prediction App</h1> |
|
</div> |
|
""" |
|
|
|
|
|
st.markdown(html_temp, unsafe_allow_html = True) |
|
|
|
st.image("https://pngimg.com/uploads/titanic/titanic_PNG36.png") |
|
|
|
|
|
st.title("Machine Learning [ Classification ]") |
|
|
|
|
|
def welcome(): |
|
return 'welcome all' |
|
|
|
|
|
features = ['sex_female', 'n_siblings_spouses_8', 'n_siblings_spouses_1', |
|
'parch_6', 'n_siblings_spouses_4', 'parch_0', 'parch_5', 'n_siblings_spouses_0', 'parch_3', |
|
'sex_male', 'Class_First', 'parch_2', 'alone_y', 'n_siblings_spouses_5', 'n_siblings_spouses_2', |
|
'n_siblings_spouses_3', 'Class_Second', 'parch_1', 'alone_n', 'Class_Third', 'parch_4'] |
|
labels = ['sex', 'age', 'n_siblings_spouses', 'parch', 'fare', 'Class', 'alone'] |
|
|
|
|
|
def predict_lr(sex, age, n_siblings_spouses, parch, fare, Class, alone): |
|
feature_names = [sex, age, n_siblings_spouses, parch, fare, Class, alone] |
|
features_df = pd.DataFrame([feature_names], columns=labels) |
|
categorical_features = ['sex', 'n_siblings_spouses', 'parch', 'Class', 'alone'] |
|
numeric_features = ['age', 'fare'] |
|
features_df[numeric_features] = scaler.transform(features_df[numeric_features]) |
|
features_df = pd.get_dummies(features_df,columns=categorical_features) |
|
|
|
c_engineering_features = set(features_df.columns) - set(numeric_features) |
|
missing_features = list(set(features) - c_engineering_features) |
|
for feature in missing_features: |
|
|
|
features_df[feature] = [0]*len(features_df) |
|
result = classifier_lr.predict(features_df) |
|
return result |
|
|
|
|
|
def predict_dt(sex, age, n_siblings_spouses, parch, fare, Class, alone): |
|
feature_names = [sex, age, n_siblings_spouses, parch, fare, Class, alone] |
|
features_df = pd.DataFrame([feature_names], columns=labels) |
|
categorical_features = ['sex', 'n_siblings_spouses', 'parch', 'Class', 'alone'] |
|
numeric_features = ['age', 'fare'] |
|
features_df[numeric_features] = scaler.transform(features_df[numeric_features]) |
|
features_df = pd.get_dummies(features_df,columns=categorical_features) |
|
|
|
c_engineering_features = set(features_df.columns) - set(numeric_features) |
|
missing_features = list(set(features) - c_engineering_features) |
|
for feature in missing_features: |
|
|
|
features_df[feature] = [0]*len(features_df) |
|
result = classifier_dt.predict(features_df) |
|
return result |
|
|
|
|
|
|
|
|
|
st.write("Male / Female") |
|
sex = st.radio("Select gender", ('male', 'female')) |
|
|
|
|
|
age = st.number_input("What is the age ?",0, 200) |
|
|
|
|
|
st.write("Number of spouses & siblings.") |
|
n_siblings_spouses = st.slider("Select the number of siblings or spouses", 0,5) |
|
|
|
|
|
st.write("Parch number ") |
|
parch = st.slider("Select parch number", 0, 6) |
|
|
|
|
|
st.write("Fare") |
|
fare = st.number_input("Thousand Dollars($)") |
|
|
|
|
|
st.write("First/Second/Third") |
|
Class = st.radio("Select Class", ('First', 'Second', 'Third')) |
|
|
|
|
|
passenger_status = st.radio("Is the passenger alone ?", ('yes', 'no')) |
|
|
|
if (passenger_status) == 'yes': |
|
alone = 'y' |
|
else: |
|
alone = 'n' |
|
|
|
|
|
|
|
|
|
def main(): |
|
|
|
options = st.radio("Available Models:", ["Logistic Regression", "Decision Tree"]) |
|
result ="" |
|
|
|
|
|
|
|
|
|
if options == "Logistic Regression": |
|
st.success("You picked {}".format(options)) |
|
|
|
if st.button('Predict'): |
|
result = predict_lr(sex, age, n_siblings_spouses, parch, fare, Class, alone) |
|
if result[0] == 0: |
|
st.error('Not a Survivor') |
|
else: |
|
st.success('A Survivor') |
|
else: |
|
st.warning("You picked {}[Less accurate]".format(options)) |
|
|
|
if st.button('Predict'): |
|
result = predict_dt(sex, age, n_siblings_spouses, parch, fare, Class, alone) |
|
if result[0] == 0: |
|
st.error('Not a Survivor') |
|
else: |
|
st.success('A Survivor') |
|
|
|
|
|
html_git = """ |
|
<h3>Checkout my GitHub</h3> |
|
<div style ="background-color:black;padding:13px"> |
|
<h1 style ="color:white;text-align:center;"><a href="https://github.com/Taoheed-O"> My GitHub link</h1> |
|
</div> |
|
""" |
|
html_linkedIn = """ |
|
<h3>Connect with me on LinkedIn</h3> |
|
<div style ="background-color:black;padding:13px"> |
|
<h1 style ="color:white;text-align:center;"><a href="https://www.linkedin.com/in/taoheed-oyeniyi"> My LinkedIn</h1> |
|
</div> |
|
""" |
|
|
|
|
|
|
|
st.markdown(html_git, unsafe_allow_html = True) |
|
st.markdown(html_linkedIn, unsafe_allow_html = True) |
|
|
|
|
|
|
|
|
|
if __name__=='__main__': |
|
main() |
|
|