Update pages/3_Life Cycle Of ML Project.py
Browse files- pages/3_Life Cycle Of ML Project.py +234 -40
pages/3_Life Cycle Of ML Project.py
CHANGED
|
@@ -1,70 +1,264 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
if 'page' not in st.session_state:
|
| 5 |
st.session_state.page = "home" # Default page is "home"
|
| 6 |
|
| 7 |
-
# Home Page
|
| 8 |
if st.session_state.page == "home":
|
| 9 |
-
st.title(":
|
| 10 |
st.markdown("Click on a stage to learn more about it.")
|
| 11 |
-
|
| 12 |
|
|
|
|
| 13 |
if st.button(":blue[π Data Collection]"):
|
| 14 |
-
st.session_state.page = "data_collection"
|
| 15 |
-
|
| 16 |
if st.button(":blue[π Problem Statement]"):
|
| 17 |
st.markdown("### Problem Statement\nIdentify the problem you want to solve and set clear objectives and success criteria.")
|
|
|
|
| 18 |
if st.button(":blue[π οΈ Simple EDA]"):
|
| 19 |
st.markdown("### Simple EDA\nPerform exploratory data analysis to understand data distributions and relationships.")
|
|
|
|
| 20 |
if st.button(":blue[Data Pre-Processing]"):
|
| 21 |
-
st.markdown("### Data Pre-Processing\
|
|
|
|
| 22 |
if st.button(":blue[π Exploratory Data Analysis (EDA)]"):
|
| 23 |
st.markdown("### Exploratory Data Analysis (EDA)\nVisualize and analyze the data to understand its distributions and relationships.")
|
|
|
|
| 24 |
if st.button(":blue[ποΈ Feature Engineering]"):
|
| 25 |
-
st.markdown("### Feature Engineering\
|
| 26 |
-
|
|
|
|
| 27 |
st.markdown("### Model Training\nTrain the model using the training data and optimize its parameters.")
|
|
|
|
| 28 |
if st.button(":blue[π§ Model Testing]"):
|
| 29 |
st.markdown("### Model Testing\nAssess the model's performance using various metrics and cross-validation techniques.")
|
|
|
|
| 30 |
if st.button(":blue[π Model Deployment]"):
|
| 31 |
st.markdown("### Model Deployment\nIntegrate the trained model into a production environment and monitor its performance.")
|
|
|
|
| 32 |
if st.button(":blue[π Monitoring]"):
|
| 33 |
st.markdown("### Monitoring\nPeriodically retrain the model with new data and update features as needed.")
|
| 34 |
|
| 35 |
-
# Data Collection Page
|
| 36 |
elif st.session_state.page == "data_collection":
|
| 37 |
-
st.title(":red[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
st.markdown("""
|
| 39 |
-
|
| 40 |
-
In the context of Machine Learning (ML), data plays an even more pivotal role. It serves as the input for algorithms, enabling them to learn, predict, and classify based on patterns found in the data. Without data, there is nothing for the ML model to learn from, and consequently, the model cannot make any predictions or inferences.
|
| 41 |
""")
|
| 42 |
-
st.markdown("
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
+
# Inject custom CSS to style the buttons
|
| 4 |
+
st.markdown("""
|
| 5 |
+
<style>
|
| 6 |
+
.stButton>button {
|
| 7 |
+
background-color: #4CAF50;
|
| 8 |
+
color: white;
|
| 9 |
+
width: 100%;
|
| 10 |
+
}
|
| 11 |
+
</style>
|
| 12 |
+
""", unsafe_allow_html=True)
|
| 13 |
+
|
| 14 |
+
# Initialize page navigation state
|
| 15 |
if 'page' not in st.session_state:
|
| 16 |
st.session_state.page = "home" # Default page is "home"
|
| 17 |
|
| 18 |
+
# ----------------- Home Page -----------------
|
| 19 |
if st.session_state.page == "home":
|
| 20 |
+
st.title(":green[Lifecycle of a Machine Learning Project]")
|
| 21 |
st.markdown("Click on a stage to learn more about it.")
|
|
|
|
| 22 |
|
| 23 |
+
# Buttons for various stages of the ML project lifecycle
|
| 24 |
if st.button(":blue[π Data Collection]"):
|
| 25 |
+
st.session_state.page = "data_collection"
|
| 26 |
+
|
| 27 |
if st.button(":blue[π Problem Statement]"):
|
| 28 |
st.markdown("### Problem Statement\nIdentify the problem you want to solve and set clear objectives and success criteria.")
|
| 29 |
+
|
| 30 |
if st.button(":blue[π οΈ Simple EDA]"):
|
| 31 |
st.markdown("### Simple EDA\nPerform exploratory data analysis to understand data distributions and relationships.")
|
| 32 |
+
|
| 33 |
if st.button(":blue[Data Pre-Processing]"):
|
| 34 |
+
st.markdown("### Data Pre-Processing\nConvert raw data into cleaned data.")
|
| 35 |
+
|
| 36 |
if st.button(":blue[π Exploratory Data Analysis (EDA)]"):
|
| 37 |
st.markdown("### Exploratory Data Analysis (EDA)\nVisualize and analyze the data to understand its distributions and relationships.")
|
| 38 |
+
|
| 39 |
if st.button(":blue[ποΈ Feature Engineering]"):
|
| 40 |
+
st.markdown("### Feature Engineering\nCreate new features from existing data.")
|
| 41 |
+
|
| 42 |
+
if st.button(":blue[π€ Model Training]"):
|
| 43 |
st.markdown("### Model Training\nTrain the model using the training data and optimize its parameters.")
|
| 44 |
+
|
| 45 |
if st.button(":blue[π§ Model Testing]"):
|
| 46 |
st.markdown("### Model Testing\nAssess the model's performance using various metrics and cross-validation techniques.")
|
| 47 |
+
|
| 48 |
if st.button(":blue[π Model Deployment]"):
|
| 49 |
st.markdown("### Model Deployment\nIntegrate the trained model into a production environment and monitor its performance.")
|
| 50 |
+
|
| 51 |
if st.button(":blue[π Monitoring]"):
|
| 52 |
st.markdown("### Monitoring\nPeriodically retrain the model with new data and update features as needed.")
|
| 53 |
|
| 54 |
+
# ----------------- Data Collection Page -----------------
|
| 55 |
elif st.session_state.page == "data_collection":
|
| 56 |
+
st.title(":red[Data Collection]")
|
| 57 |
+
st.markdown("### Data Collection\nThis page discusses the process of Data Collection.")
|
| 58 |
+
st.markdown("Types of Data: **Structured**, **Unstructured**, **Semi-Structured**")
|
| 59 |
+
|
| 60 |
+
if st.button(":blue[π Structured Data]"):
|
| 61 |
+
st.session_state.page = "structured_data"
|
| 62 |
+
|
| 63 |
+
if st.button(":blue[π· Unstructured Data]"):
|
| 64 |
+
st.session_state.page = "unstructured_data"
|
| 65 |
+
|
| 66 |
+
if st.button(":blue[ποΈ Semi-Structured Data]"):
|
| 67 |
+
st.session_state.page = "semi_structured_data"
|
| 68 |
+
|
| 69 |
+
if st.button("Back to Home"):
|
| 70 |
+
st.session_state.page = "home"
|
| 71 |
+
|
| 72 |
+
# ----------------- Structured Data Page -----------------
|
| 73 |
+
elif st.session_state.page == "structured_data":
|
| 74 |
+
st.title(":blue[Structured Data]")
|
| 75 |
st.markdown("""
|
| 76 |
+
Structured data is highly organized and typically stored in tables like spreadsheets or databases. It is easy to search and analyze.
|
|
|
|
| 77 |
""")
|
| 78 |
+
st.markdown("### Examples: Excel files, CSV files")
|
| 79 |
+
|
| 80 |
+
if st.button(":green[π Excel]"):
|
| 81 |
+
st.session_state.page = "excel"
|
| 82 |
+
|
| 83 |
+
if st.button("Back to Data Collection"):
|
| 84 |
+
st.session_state.page = "data_collection"
|
| 85 |
+
|
| 86 |
+
# ----------------- Excel Data Page -----------------
|
| 87 |
+
elif st.session_state.page == "excel":
|
| 88 |
+
st.title(":green[Excel Data Format]")
|
| 89 |
+
|
| 90 |
+
st.write("### What is Excel?")
|
| 91 |
+
st.write("Excel is a spreadsheet tool for storing data in tabular format with rows and columns. Common file extensions: .xls, .xlsx.")
|
| 92 |
+
|
| 93 |
+
st.write("### How to Read Excel Files")
|
| 94 |
+
st.code("""
|
| 95 |
+
import pandas as pd
|
| 96 |
+
|
| 97 |
+
# Read an Excel file
|
| 98 |
+
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
|
| 99 |
+
print(df)
|
| 100 |
+
""", language='python')
|
| 101 |
+
|
| 102 |
+
st.write("### Issues Encountered")
|
| 103 |
+
st.write("""
|
| 104 |
+
- **File not found**: Incorrect file path.
|
| 105 |
+
- **Sheet name error**: Specified sheet doesn't exist.
|
| 106 |
+
- **Missing libraries**: openpyxl or xlrd might be missing.
|
| 107 |
+
""")
|
| 108 |
+
|
| 109 |
+
st.write("### Solutions to These Issues")
|
| 110 |
+
st.code("""
|
| 111 |
+
# Install required libraries
|
| 112 |
+
# pip install openpyxl xlrd
|
| 113 |
+
|
| 114 |
+
# Handle missing file
|
| 115 |
+
try:
|
| 116 |
+
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
|
| 117 |
+
except FileNotFoundError:
|
| 118 |
+
print("File not found. Check the file path.")
|
| 119 |
+
|
| 120 |
+
# List available sheet names
|
| 121 |
+
excel_file = pd.ExcelFile('data.xlsx')
|
| 122 |
+
print(excel_file.sheet_names)
|
| 123 |
+
""", language='python')
|
| 124 |
+
|
| 125 |
+
# Download button for a sample Jupyter notebook
|
| 126 |
+
with open("excel_handling_guide.ipynb", "rb") as file:
|
| 127 |
+
st.download_button(
|
| 128 |
+
label="Download Jupyter Notebook",
|
| 129 |
+
data=file,
|
| 130 |
+
file_name="excel_handling_guide.ipynb",
|
| 131 |
+
mime="application/octet-stream"
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
if st.button("Back to Structured Data"):
|
| 135 |
+
st.session_state.page = "structured_data"
|
| 136 |
+
|
| 137 |
+
# ----------------- Unstructured Data Page -----------------
|
| 138 |
+
elif st.session_state.page == "unstructured_data":
|
| 139 |
+
st.title(":blue[Unstructured Data]")
|
| 140 |
|
| 141 |
+
st.markdown("""
|
| 142 |
+
**Unstructured data** does not have a predefined format. It consists of various data types like text, images, videos, and audio files.
|
| 143 |
+
Examples include:
|
| 144 |
+
- Text documents (e.g., .txt, .docx)
|
| 145 |
+
- Images (e.g., .jpg, .png)
|
| 146 |
+
- Videos (e.g., .mp4, .avi)
|
| 147 |
+
- Audio files (e.g., .mp3, .wav)
|
| 148 |
+
- Social media posts
|
| 149 |
+
""")
|
| 150 |
+
|
| 151 |
+
st.header("π Handling Text Data")
|
| 152 |
+
st.markdown("""
|
| 153 |
+
Text data can be analyzed using Natural Language Processing (NLP) techniques.
|
| 154 |
+
""")
|
| 155 |
+
st.code("""
|
| 156 |
+
# Reading text data
|
| 157 |
+
with open('sample.txt', 'r') as file:
|
| 158 |
+
text = file.read()
|
| 159 |
+
print(text)
|
| 160 |
+
|
| 161 |
+
# Basic text processing using NLTK
|
| 162 |
+
import nltk
|
| 163 |
+
from nltk.tokenize import word_tokenize
|
| 164 |
+
|
| 165 |
+
nltk.download('punkt')
|
| 166 |
+
tokens = word_tokenize(text)
|
| 167 |
+
print(tokens)
|
| 168 |
+
""", language='python')
|
| 169 |
+
|
| 170 |
+
st.header("πΌοΈ Handling Image Data")
|
| 171 |
+
st.markdown("""
|
| 172 |
+
Image data can be processed using libraries like OpenCV and PIL (Pillow).
|
| 173 |
+
""")
|
| 174 |
+
st.code("""
|
| 175 |
+
from PIL import Image
|
| 176 |
+
|
| 177 |
+
# Open an image file
|
| 178 |
+
image = Image.open('sample_image.jpg')
|
| 179 |
+
image.show()
|
| 180 |
+
|
| 181 |
+
# Convert image to grayscale
|
| 182 |
+
gray_image = image.convert('L')
|
| 183 |
+
gray_image.show()
|
| 184 |
+
""", language='python')
|
| 185 |
+
|
| 186 |
+
st.header("π₯ Handling Video Data")
|
| 187 |
+
st.markdown("""
|
| 188 |
+
Videos can be processed frame by frame using OpenCV.
|
| 189 |
+
""")
|
| 190 |
+
st.code("""
|
| 191 |
+
import cv2
|
| 192 |
+
|
| 193 |
+
# Capture video
|
| 194 |
+
video = cv2.VideoCapture('sample_video.mp4')
|
| 195 |
+
|
| 196 |
+
while video.isOpened():
|
| 197 |
+
ret, frame = video.read()
|
| 198 |
+
if not ret:
|
| 199 |
+
break
|
| 200 |
+
cv2.imshow('Frame', frame)
|
| 201 |
+
if cv2.waitKey(25) & 0xFF == ord('q'):
|
| 202 |
+
break
|
| 203 |
+
|
| 204 |
+
video.release()
|
| 205 |
+
cv2.destroyAllWindows()
|
| 206 |
+
""", language='python')
|
| 207 |
+
|
| 208 |
+
st.header("π Handling Audio Data")
|
| 209 |
+
st.markdown("""
|
| 210 |
+
Audio data can be handled using libraries like librosa.
|
| 211 |
+
""")
|
| 212 |
+
st.code("""
|
| 213 |
+
import librosa
|
| 214 |
+
import librosa.display
|
| 215 |
+
import matplotlib.pyplot as plt
|
| 216 |
+
|
| 217 |
+
# Load audio file
|
| 218 |
+
y, sr = librosa.load('sample_audio.mp3')
|
| 219 |
+
librosa.display.waveshow(y, sr=sr)
|
| 220 |
+
plt.title('Waveform')
|
| 221 |
+
plt.show()
|
| 222 |
+
""", language='python')
|
| 223 |
+
|
| 224 |
+
st.markdown("### Challenges with Unstructured Data")
|
| 225 |
+
st.write("""
|
| 226 |
+
- **Noise and Inconsistency**: Data is often incomplete or noisy.
|
| 227 |
+
- **Storage Requirements**: Large size and variability in data types.
|
| 228 |
+
- **Processing Time**: Analyzing unstructured data is computationally expensive.
|
| 229 |
+
""")
|
| 230 |
+
|
| 231 |
+
st.markdown("### Solutions")
|
| 232 |
+
st.write("""
|
| 233 |
+
- **Data Cleaning**: Preprocess data to remove noise.
|
| 234 |
+
- **Efficient Storage**: Use NoSQL databases (e.g., MongoDB) or cloud storage.
|
| 235 |
+
- **Parallel Processing**: Utilize frameworks like Apache Spark.
|
| 236 |
+
""")
|
| 237 |
+
|
| 238 |
+
# Back to Data Collection
|
| 239 |
+
if st.button("Back to Data Collection"):
|
| 240 |
+
st.session_state.page = "data_collection"
|
| 241 |
+
|
| 242 |
+
# ----------------- Semi-Structured Data Page -----------------
|
| 243 |
+
elif st.session_state.page == "semi_structured_data":
|
| 244 |
+
st.title(":blue[Semi-Structured Data]")
|
| 245 |
|
| 246 |
+
st.markdown("""
|
| 247 |
+
**Semi-structured data** does not conform strictly to a tabular structure but contains tags or markers to separate elements. Examples include:
|
| 248 |
+
- JSON (JavaScript Object Notation) files
|
| 249 |
+
- XML (Extensible Markup Language) files
|
| 250 |
+
- YAML (Yet Another Markup Language)
|
| 251 |
+
""")
|
| 252 |
+
|
| 253 |
+
st.header("πΉ JSON Data")
|
| 254 |
+
st.markdown("""
|
| 255 |
+
JSON is a popular format for storing and exchanging data.
|
| 256 |
+
""")
|
| 257 |
+
st.code("""
|
| 258 |
+
# Sample JSON data
|
| 259 |
+
data = '''
|
| 260 |
+
{
|
| 261 |
+
"name": "Alice",
|
| 262 |
+
"age": 25,
|
| 263 |
+
"skills": ["Python", "Machine Learning"]
|
| 264 |
+
}
|