Prerequisites and Required Libraries

Learn how to install the libraries required to create Streamlit applications.

In this chapter we’ll build a logistic regression model to predict if a person could survive the Titanic disaster. After building the model, we’ll use Streamlit to build a web app and a UI for it. The web app will let the user input values and get the predicted results.

Prerequisites

This chapter is focused on Streamlit and assumes familiarity with the following:

  • Programming in Python.

  • Data cleaning and other standard techniques such as numerical encoding and one-hot encoding.

  • Familiarity with the scikit-learn library.

  • Familiarity with logistic Regression will help but is not strictly necessary.

  • Familiarity with the pandas library.

  • Basic understanding of the Matplotlib library.

Install the required libraries

First, we’ll need to create a virtual environment to manage and install the required packages: streamlit, scikit-learn, pandas, and matplotlib.

python -m venv venv
venv/Scripts/activate
pip install streamlit , scikit-learn , pandas , matplotlib

Installation confirmation

Once the installation is complete, we can type the following command: streamlit hello

Let’s type streamlit hello in the following terminal to confirm the installation.

Terminal 1
Terminal
Loading...

Import the required libraries

We’ll import all the following libraries:

import streamlit as st
import pandas as pd
from sklearn.linear_model import LogisticRegression
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import confusion_matrix
import matplotlib.pyplot as plt