sree4411 commited on
Commit
1fcc334
Β·
verified Β·
1 Parent(s): 58c80cb

Update pages/3_Life Cycle Of ML Project.py

Browse files
Files changed (1) hide show
  1. 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
- # page navigation
 
 
 
 
 
 
 
 
 
 
 
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(":red[Lifecycle of a Machine Learning Project]")
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" # Redirect to 'data_collection' page
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\nHere we convert raw data into cleaned data.")
 
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\nHere we can create our own new features.")
26
- if st.button(":blue[Model Training]"):
 
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 (Triggered when "Data Collection" is clicked)
36
  elif st.session_state.page == "data_collection":
37
- st.title(":red[What is Data?]")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  st.markdown("""
39
- ### What is Data?\nData is a collection of raw information from various sources. On its own, it may not carry any immediate meaning, but when processed and analyzed, it can be used to derive insights, make decisions, and support the development of systems across various fields, such as business, science, engineering, and more.
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(""":blue[Types of Data]:
43
- Data is divided into Three Types.
44
- \nStructured
45
- \nUnstructured
46
- \nSemi-Structured""")
47
-
48
- # Button for Structured Data
49
- if st.button(":blue[🌟 Structured Data]"):
50
- st.session_state.page = "Structured Data"
51
- elif st.session_state.page == "Structured Data":
52
- st.markdown("### Structured Data\nStructured data is highly organized and typically stored in tables like spreadsheets or databases. It is easy to search and analyze.")
53
- st.markdown("Examples: Excel files, CSV files")
54
-
55
-
56
- # Button for Unstructured Data
57
- if st.button(":blue[🌟 Unstructured Data]"):
58
- st.markdown("### Unstructured Data\nUnstructured data does not have a predefined format and is often text-heavy, like emails, videos, or social media posts.")
59
- st.markdown("Examples: Text files, images, video files")
60
- # Add specific content related to Unstructured Data (e.g., natural language processing, handling images, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
 
62
- # Button for Semi-Structured Data
63
- if st.button(":blue[🌟 Semi-Structured Data]"):
64
- st.markdown("### Semi-Structured Data\nSemi-structured data does not conform to a rigid structure but still has some organizational properties, often in the form of tags or markers.")
65
- st.markdown("Examples: JSON, XML files")
66
- # Add specific content related to Semi-Structured Data (e.g., parsing JSON, XML handling, etc.)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- # Button to go back to home page
69
- if st.button("Back to Home"):
70
- st.session_state.page = "home" # Go back to the home page
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }