File size: 10,549 Bytes
66b2688
6fd8b9a
 
 
66b2688
0ad3418
 
 
 
 
 
 
 
 
 
 
 
66b2688
 
 
 
 
 
 
 
0ad3418
 
66b2688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad3418
66b2688
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad3418
66b2688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad3418
66b2688
 
 
 
 
 
 
 
 
 
 
 
 
 
0ad3418
 
 
 
 
 
 
 
 
 
 
 
66b2688
0ad3418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66b2688
 
 
 
6fd8b9a
66b2688
 
 
 
0ad3418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66b2688
0ad3418
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66b2688
 
 
 
6fd8b9a
66b2688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fd8b9a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import streamlit as st
import pandas as pd
import json
import xml.etree.ElementTree as ET

# Inject custom CSS to style the buttons
st.markdown("""
    <style>
    .stButton>button {
        background-color: #4CAF50;
        color: white;
        width: 100%;
    }
    </style>
    """, unsafe_allow_html=True)

# Initialize page navigation state
if 'page' not in st.session_state:
    st.session_state.page = "home"  # Default page is "home"

# ----------------- Home Page -----------------
def home_page():
    st.title(":green[Lifecycle of a Machine Learning Project]")
    st.markdown("Click on a stage to learn more about it.")

    # Buttons for various stages of the ML project lifecycle
    if st.button(":blue[πŸ“Š Data Collection]"):
        st.session_state.page = "data_collection"

    if st.button(":blue[🌟 Problem Statement]"):
        st.markdown("### Problem Statement\nIdentify the problem you want to solve and set clear objectives and success criteria.")
    
    if st.button(":blue[πŸ› οΈ Simple EDA]"):
        st.markdown("### Simple EDA\nPerform exploratory data analysis to understand data distributions and relationships.")
    
    if st.button(":blue[Data Pre-Processing]"):
        st.markdown("### Data Pre-Processing\nConvert raw data into cleaned data.")

    if st.button(":blue[πŸ“ˆ Exploratory Data Analysis (EDA)]"):
        st.markdown("### Exploratory Data Analysis (EDA)\nVisualize and analyze the data to understand its distributions and relationships.")

    if st.button(":blue[πŸ‹οΈ Feature Engineering]"):
        st.markdown("### Feature Engineering\nCreate new features from existing data.")

    if st.button(":blue[πŸ€– Model Training]"):
        st.markdown("### Model Training\nTrain the model using the training data and optimize its parameters.")

    if st.button(":blue[πŸ”§ Model Testing]"):
        st.markdown("### Model Testing\nAssess the model's performance using various metrics and cross-validation techniques.")

    if st.button(":blue[πŸš€ Model Deployment]"):
        st.markdown("### Model Deployment\nIntegrate the trained model into a production environment and monitor its performance.")

    if st.button(":blue[πŸ“ Monitoring]"):
        st.markdown("### Monitoring\nPeriodically retrain the model with new data and update features as needed.")

# ----------------- Data Collection Page -----------------
def data_collection_page():
    st.title(":red[Data Collection]")
    st.markdown("### Data Collection\nThis page discusses the process of Data Collection.")
    st.markdown("Types of Data: **Structured**, **Unstructured**, **Semi-Structured**")

    if st.button(":blue[🌟 Structured Data]"):
        st.session_state.page = "structured_data"

    if st.button(":blue[πŸ“· Unstructured Data]"):
        st.session_state.page = "unstructured_data"

    if st.button(":blue[πŸ—ƒοΈ Semi-Structured Data]"):
        st.session_state.page = "semi_structured_data"

    if st.button("Back to Home"):
        st.session_state.page = "home"

# ----------------- Structured Data Page -----------------
def structured_data_page():
    st.title(":blue[Structured Data]")
    st.markdown("""
    Structured data is highly organized and typically stored in tables like spreadsheets or databases. It is easy to search and analyze.
    """)
    st.markdown("### Examples: Excel files, CSV files")

    if st.button(":green[πŸ“Š Excel]"):
        st.session_state.page = "excel"

    if st.button("Back to Data Collection"):
        st.session_state.page = "data_collection"

# ----------------- Excel Data Page -----------------
def excel_page():
    st.title(":green[Excel Data Format]")

    st.write("### What is Excel?")
    st.write("Excel is a spreadsheet tool for storing data in tabular format with rows and columns. Common file extensions: .xls, .xlsx.")

    st.write("### How to Read Excel Files")
    st.code("""
import pandas as pd

# Read an Excel file
df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
print(df)
    """, language='python')

    st.write("### Issues Encountered")
    st.write("""
- **File not found**: Incorrect file path.
- **Sheet name error**: Specified sheet doesn't exist.
- **Missing libraries**: openpyxl or xlrd might be missing.
""")

    st.write("### Solutions to These Issues")
    st.code("""
# Install required libraries
# pip install openpyxl xlrd

# Handle missing file
try:
    df = pd.read_excel('data.xlsx', sheet_name='Sheet1')
except FileNotFoundError:
    print("File not found. Check the file path.")

# List available sheet names
excel_file = pd.ExcelFile('data.xlsx')
print(excel_file.sheet_names)
    """, language='python')

    # Download button for a sample Jupyter notebook
    with open("excel_handling_guide.ipynb", "rb") as file:
        st.download_button(
            label="Download Jupyter Notebook",
            data=file,
            file_name="excel_handling_guide.ipynb",
            mime="application/octet-stream"
        )

    if st.button("Back to Structured Data"):
        st.session_state.page = "structured_data"

# ----------------- Unstructured Data Page -----------------
def unstructured_data_page():
    st.title(":blue[Unstructured Data]")
    
    st.markdown("""
    **Unstructured data** does not have a predefined format. It consists of various data types like text, images, videos, and audio files.
    Examples include:
    - Text documents (e.g., .txt, .docx)
    - Images (e.g., .jpg, .png)
    - Videos (e.g., .mp4, .avi)
    - Audio files (e.g., .mp3, .wav)
    - Social media posts
    """)

    st.header("πŸ“„ Handling Text Data")
    st.markdown("""
    Text data can be analyzed using Natural Language Processing (NLP) techniques.
    """)
    st.code("""
# Reading text data
with open('sample.txt', 'r') as file:
    text = file.read()
    print(text)

# Basic text processing using NLTK
import nltk
from nltk.tokenize import word_tokenize

nltk.download('punkt')
tokens = word_tokenize(text)
print(tokens)
    """, language='python')

    st.header("πŸ–ΌοΈ Handling Image Data")
    st.markdown("""
    Image data can be processed using libraries like OpenCV and PIL (Pillow).
    """)
    st.code("""
from PIL import Image

# Open an image file
image = Image.open('sample_image.jpg')
image.show()

# Convert image to grayscale
gray_image = image.convert('L')
gray_image.show()
    """, language='python')

    st.header("πŸŽ₯ Handling Video Data")
    st.markdown("""
    Videos can be processed frame by frame using OpenCV.
    """)
    st.code("""
import cv2

# Capture video
video = cv2.VideoCapture('sample_video.mp4')

while video.isOpened():
    ret, frame = video.read()
    if not ret:
        break
    cv2.imshow('Frame', frame)
    if cv2.waitKey(25) & 0xFF == ord('q'):
        break

video.release()
cv2.destroyAllWindows()
    """, language='python')

    st.header("πŸ”Š Handling Audio Data")
    st.markdown("""
    Audio data can be handled using libraries like librosa.
    """)
    st.code("""
import librosa
import librosa.display
import matplotlib.pyplot as plt

# Load audio file
y, sr = librosa.load('sample_audio.mp3')
librosa.display.waveshow(y, sr=sr)
plt.title('Waveform')
plt.show()
    """, language='python')

    st.markdown("### Challenges with Unstructured Data")
    st.write("""
    - **Noise and Inconsistency**: Data is often incomplete or noisy.
    - **Storage Requirements**: Large size and variability in data types.
    - **Processing Time**: Analyzing unstructured data is computationally expensive.
    """)

    st.markdown("### Solutions")
    st.write("""
    - **Data Cleaning**: Preprocess data to remove noise.
    - **Efficient Storage**: Use NoSQL databases (e.g., MongoDB) or cloud storage.
    - **Parallel Processing**: Utilize frameworks like Apache Spark.
    """)

    # Back to Data Collection
    if st.button("Back to Data Collection"):
        st.session_state.page = "data_collection"

# ----------------- Semi-Structured Data Page -----------------
def semi_structured_data_page():
    st.title(":blue[Semi-Structured Data]")
    
    st.markdown("""
    **Semi-structured data** does not conform strictly to a tabular structure but contains tags or markers to separate elements. Examples include:
    - JSON (JavaScript Object Notation) files
    - XML (Extensible Markup Language) files
    - YAML (Yet Another Markup Language)
    """)

    st.header("πŸ”Ή JSON Data")
    st.markdown("""
    JSON is a popular format for storing and exchanging data.
    """)
    st.code("""
# Sample JSON data
data = '''
{
    "name": "Alice",
    "age": 25,
    "skills": ["Python", "Machine Learning"]
}
'''

# Parse JSON
parsed_data = json.loads(data)
print(parsed_data['name'])  # Output: Alice
    """, language='python')

    st.header("πŸ”Ή Reading JSON Files")
    st.code("""
# Reading a JSON file
with open('data.json', 'r') as file:
    data = json.load(file)
    print(data)
    """, language='python')

    st.header("πŸ”Ή XML Data")
    st.markdown("""
    XML is a markup language that defines a set of rules for encoding documents.
    """)
    st.code("""
import xml.etree.ElementTree as ET

# Sample XML data
xml_data = '''
<person>
    <name>Bob</name>
    <age>30</age>
    <city>New York</city>
</person>
'''

# Parse XML
root = ET.fromstring(xml_data)
print(root.find('name').text)  # Output: Bob
    """, language='python')

    st.markdown("### Challenges with Semi-Structured Data")
    st.write("""
    - **Complex Parsing**: Requires specialized parsers.
    - **Nested Data**: Can be deeply nested, making it harder to process.
    """)

    st.markdown("### Solutions")
    st.write("""
    - **Libraries**: Use libraries like json, xml.etree.ElementTree, and yaml for parsing.
    - **Validation**: Validate data formats to avoid parsing errors.
    """)

    # Back to Data Collection
    if st.button("Back to Data Collection"):
        st.session_state.page = "data_collection"

# ----------------- Router -----------------
def router():
    if st.session_state.page == "home":
        home_page()
    elif st.session_state.page == "data_collection":
        data_collection_page()
    elif st.session_state.page == "structured_data":
        structured_data_page()
    elif st.session_state.page == "excel":
        excel_page()
    elif st.session_state.page == "unstructured_data":
        unstructured_data_page()
    elif st.session_state.page == "semi_structured_data":
        semi_structured_data_page()

# Run the router function
if __name__ == "__main__":
   router()