|
import streamlit as st |
|
import pandas as pd |
|
import json |
|
import xml.etree.ElementTree as ET |
|
from PIL import Image |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.stButton>button { |
|
background-color: #4CAF50; |
|
color: white; |
|
width: 100%; |
|
} |
|
</style> |
|
""", unsafe_allow_html=True) |
|
|
|
|
|
if 'page' not in st.session_state: |
|
st.session_state.page = "home" |
|
|
|
|
|
def home_page(): |
|
st.title(":green[Lifecycle of a Machine Learning Project]") |
|
st.markdown("Click on a stage to learn more about it.") |
|
|
|
|
|
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.") |
|
|
|
|
|
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" |
|
|
|
|
|
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") |
|
|
|
if st.button(":green[π Excel]"): |
|
st.session_state.page = "excel" |
|
|
|
if st.button("Back to Data Collection"): |
|
st.session_state.page = "data_collection" |
|
|
|
|
|
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') |
|
|
|
st.markdown('[Jupyter Notebook](https://colab.research.google.com/drive/1Dv68m9hcRzXsLRlRit0uZc-8CB8U6VV3?usp=sharing)') |
|
|
|
if st.button("Back to Structured Data"): |
|
st.session_state.page = "structured_data" |
|
|
|
|
|
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: |
|
- Images (e.g., .jpg, .png) |
|
- Videos (e.g., .mp4, .avi) |
|
- Social media posts |
|
""") |
|
|
|
|
|
if st.button("Introduction to Image"): |
|
st.session_state.page = "introduction_to_image" |
|
|
|
def image(): |
|
st.header("πΌοΈ What is Image") |
|
st.markdown(""" |
|
An image is a two-dimensional visual representation of objects, people, scenes, or concepts. It can be captured using devices like cameras, scanners, or created digitally. Images are composed of individual units called pixels, which contain information about brightness and color. |
|
|
|
Types of Images: |
|
- **Raster Images (Bitmap)**: Composed of a grid of pixels. Common formats include: |
|
- JPEG |
|
- PNG |
|
- GIF |
|
- **Vector Images**: Defined by mathematical equations and geometric shapes like lines and curves. Common format: |
|
- SVG (Scalable Vector Graphics) |
|
- **3D Images**: Represent objects or scenes in three dimensions, often used for rendering and modeling. |
|
|
|
Image Representation: |
|
- **Grayscale Image**: Each pixel has a single intensity value, typically ranging from 0 (black) to 255 (white), representing different shades of gray. |
|
- **Color Image**: Usually represented in the RGB color space, where each pixel consists of three values indicating the intensity of Red, Green, and Blue. |
|
|
|
Applications of Images: |
|
- **Photography & Visual Media**: Capturing moments and storytelling. |
|
- **Medical Imaging**: Diagnosing conditions using X-rays, MRIs, etc. |
|
- **Machine Learning & AI**: Tasks like image classification, object detection, and facial recognition. |
|
- **Remote Sensing**: Analyzing geographic and environmental data using satellite imagery. |
|
- **Graphic Design & Art**: Creating creative visual content for marketing and design. |
|
""") |
|
|
|
st.code(""" |
|
from PIL import Image |
|
import numpy as np |
|
import matplotlib.pyplot as plt |
|
|
|
# Open an image file |
|
image = Image.open('sample_image.jpg') |
|
image.show() |
|
|
|
# Convert image to grayscale |
|
gray_image = image.convert('L') |
|
gray_image.show() |
|
|
|
# Resize the image |
|
resized_image = image.resize((200, 200)) |
|
resized_image.show() |
|
|
|
# Rotate the image by 90 degrees |
|
rotated_image = image.rotate(90) |
|
rotated_image.show() |
|
|
|
# Convert the image to a NumPy array and display its shape |
|
image_array = np.array(image) |
|
print(image_array.shape) |
|
|
|
# Display the image array as a plot |
|
plt.imshow(image) |
|
plt.title("Original Image") |
|
plt.axis('off') |
|
plt.show() |
|
""", language='python') |
|
|
|
st.header(" Color Spaces in Machine Learning") |
|
st.markdown(""" |
|
A color space is a mathematical model for representing colors. In machine learning, different color spaces can be used for preprocessing and analyzing image data, depending on the task. |
|
|
|
Common Color Spaces: |
|
- **RGB (Red, Green, Blue)**: The most common color space for digital images. Each pixel is represented by a combination of three values corresponding to the red, green, and blue channels. |
|
- **Use Cases**: Image classification, general-purpose image analysis. |
|
- **HSV (Hue, Saturation, Value)**: Separates color information (hue) from intensity (value), making it useful for tasks where distinguishing between color variations and intensity is important. |
|
- **Use Cases**: Color-based object detection, image segmentation, color tracking. |
|
- **CMYK (Cyan, Magenta, Yellow, Black)**: Primarily used for printing, not commonly used in machine learning, but useful for preparing images for printers. |
|
- **Use Cases**: Printing applications. |
|
- **LAB (Lightness, A, B)**: Designed to be perceptually uniform, meaning that the perceptual difference between colors is consistent across the space. |
|
- **Use Cases**: Color correction, image processing tasks requiring color consistency. |
|
""") |
|
|
|
|
|
if st.button("Back to Data Collection"): |
|
st.session_state.page = "data_collection" |
|
|
|
|
|
def semi_structured_data_page(): |
|
st.title(":orange[Semi-Structured Data]") |
|
st.markdown(""" |
|
Semi-structured data does not follow the rigid structure of relational databases but still has some organizational properties. Examples include: |
|
- JSON files |
|
- XML files |
|
""") |
|
|
|
if st.button(":green[πΎ JSON]"): |
|
st.session_state.page = "json" |
|
|
|
if st.button(":green[π CSV]"): |
|
st.session_state.page = "csv" |
|
|
|
if st.button(":green[π XML]"): |
|
st.session_state.page = "xml" |
|
|
|
if st.button("Back to Data Collection"): |
|
st.session_state.page = "data_collection" |
|
|
|
|
|
def json_page(): |
|
st.title(":green[JSON Data Format]") |
|
|
|
st.write("### What is JSON?") |
|
st.write(""" |
|
JSON (JavaScript Object Notation) is a lightweight data-interchange format that's easy for humans to read and write, and easy for machines to parse and generate. JSON is often used in APIs, configuration files, and data transfer applications. |
|
""") |
|
|
|
st.write("### Reading JSON Files") |
|
st.code(""" |
|
import json |
|
# Read a JSON file |
|
with open('data.json', 'r') as file: |
|
data = json.load(file) |
|
print(data) |
|
""", language='python') |
|
|
|
st.write("### Writing JSON Files") |
|
st.code(""" |
|
import json |
|
# Write data to JSON file |
|
data = { |
|
"name": "Alice", |
|
"age": 25, |
|
"skills": ["Python", "Machine Learning"] |
|
} |
|
with open('data.json', 'w') as file: |
|
json.dump(data, file, indent=4) |
|
""", language='python') |
|
|
|
st.markdown("### Tips for Handling JSON Files") |
|
st.write(""" |
|
- JSON files can be nested, so you might need to navigate through dictionaries and lists. |
|
- If the structure is complex, you can use libraries like json_normalize() in pandas to flatten the JSON into a more tabular format for easier analysis. |
|
- JSON supports both strings and numbers, and other types like arrays and booleans, making it versatile for various data types. |
|
""") |
|
|
|
st.markdown('[Jupyter Notebook](https://huggingface.co/transformers/notebooks.html)') |
|
|
|
if st.button("Back to Semi-Structured Data"): |
|
st.session_state.page = "semi_structured_data" |
|
|
|
|
|
def main(): |
|
page = st.session_state.page |
|
|
|
if page == "home": |
|
home_page() |
|
elif page == "data_collection": |
|
data_collection_page() |
|
elif page == "structured_data": |
|
structured_data_page() |
|
elif page == "excel": |
|
excel_page() |
|
elif page == "unstructured_data": |
|
unstructured_data_page() |
|
elif page == "semi_structured_data": |
|
semi_structured_data_page() |
|
elif page == "json": |
|
json_page() |
|
elif page == "image": |
|
image() |
|
|
|
if __name__ == "__main__": |
|
main() |
|
|