Scale the feature data scaler = StandardScaler() We will use a 70–30 ratio to split the dataset. X_train, X_test, y_train, y_test = train_test_split(features, survival ,test_size = 0.3) Train-test split train_df = manipulate_df(train_df)įeatures= train_df] Since we are not focused on building the model, we will only select 6 features from our dataframe.We use one-hot-encoding for the Pclass.We use the mean value to fill the missing data in the age columns.For the sex column, we set a value of 0 if the passenger is male and 1 if the passenger is female.Manipulate data def manipulate_df(df):ĭf = df.map(lambda x: 0 if x = 'male' else 1)ĭf.fillna(value = df.mean(), inplace = True)ĭf = df.map(lambda x: 1 if x = 1 else 0)ĭf = df.map(lambda x: 1 if x = 2 else 0)ĭf = df.map(lambda x: 1 if x = 3 else 0)ĭf= df] We will define a function to transform our data to make it useable for our Logistic Regression Model. Fill the missing values in the age column.Use one-hot encoding on the feature ‘Pclass.’.Assign a numerical value to the feature ‘Sex.’.We need to perform the following on our data before our Logistic Regression Model can use it. You can print the dataframe to check the columns inside it. We import the dataset and create a dataframe. You can download the dataset from Kaggle. Import matplotlib.pyplot as plt Logistic regression modelįirst, we will load the Titanic dataset and manipulate our dataset to meet our requirements. import streamlit as stįrom sklearn.linear_model import LogisticRegressionįrom sklearn.model_selection import train_test_splitįrom sklearn.preprocessing import StandardScalerįrom trics import confusion_matrix We will need to import all the installed libraries. You can press ctrl+C on the command line to stop the app. This should launch a sample Streamlit app. Once the installation is complete, type the following command to ensure that streamlit has been installed as expected. Pip install streamlit,scikit-learn, pandas, matplotlibįirst, we will need to create a virtual environment to manage our packages and install the required packages: streamlit,scikit-learn, pandas, and matplotlib. Installing required libraries python -m venv venv Basic Understanding of Matplotlib library.Familiarity with Logistic Regression helps but is not necessary.Familiarity with the scikit-learn library.A basic understanding of data cleaning and standard techniques such as numerical-encoding, one-hot-encoding.This tutorial is focused on Streamlit, so familiarity with building ML models using scikit-learn is expected. The web app will let the user input values and get the predicted results. After building the model, we will use Streamlit to build a web app and a UI for our Model. This tutorial will build a Logistic Regression Model to predict if a person would survive the Titanic disaster. It’s open-source, and you can create your widgets if needed.Easy to deploy Streamlit apps using Streamlit sharing.It has many prebuilt widgets available, further reducing the time you spend on building the UI.You don’t need to deal with HTML/CSS/JSS.Building a UI lets users use your model in a more user-friendly format. But, using Streamlit, you can create a clean UI for your model and showcase it to others. Most models die inside a Jupyter notebook and are not appealing. Streamlit is a Python library that helps us develop UIs for our models without HTML/CSS/JS. Conclusion Why should you use Streamlit?.It is easy to learn, and a few lines of code can create a beautiful web app. Streamlit is an open-source Python library that can build a UI for various purposes, it is not limited to data apps/machine learning.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |