Spaces:
Sleeping
Sleeping
Update pages/8Model Training.py
Browse files- pages/8Model Training.py +135 -11
pages/8Model Training.py
CHANGED
|
@@ -20,14 +20,138 @@ if "current_page" not in st.session_state:
|
|
| 20 |
def navigate_to(page_name):
|
| 21 |
st.session_state.current_page = page_name
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
#
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
def navigate_to(page_name):
|
| 21 |
st.session_state.current_page = page_name
|
| 22 |
|
| 23 |
+
import streamlit as st
|
| 24 |
+
|
| 25 |
+
st.set_page_config(page_title="Model Building", layout="wide")
|
| 26 |
+
|
| 27 |
+
st.markdown("""
|
| 28 |
+
<h1 style="text-align: center; color: #BB3385;">🛠️ Model Building</h1>
|
| 29 |
+
<p style="text-align: center; font-size: 18px;">Welcome to one of the most exciting parts of machine learning – teaching the machine how to learn!</p>
|
| 30 |
+
""", unsafe_allow_html=True)
|
| 31 |
+
|
| 32 |
+
# What is Training?
|
| 33 |
+
st.markdown("## 🤖 So, What is Model Training?")
|
| 34 |
+
st.markdown("""
|
| 35 |
+
Imagine you're a teacher. You give your student (the machine) a bunch of examples and slowly help them learn from it. That’s exactly what model training is.
|
| 36 |
+
|
| 37 |
+
We give the machine:
|
| 38 |
+
- Some data (like past examples)
|
| 39 |
+
- A method to learn (called an algorithm)
|
| 40 |
+
|
| 41 |
+
Together, this helps the machine **learn patterns** so it can make decisions or predictions in the future.
|
| 42 |
+
""")
|
| 43 |
+
|
| 44 |
+
# Who are we training?
|
| 45 |
+
st.markdown("## 👨💻 Who are we actually training?")
|
| 46 |
+
st.markdown("""
|
| 47 |
+
We are not training a robot or a human.
|
| 48 |
+
We are training a **mathematical brain** – called a machine learning model.
|
| 49 |
+
|
| 50 |
+
You can think of this model like a **blank notebook**.
|
| 51 |
+
We (programmers) guide it using:
|
| 52 |
+
- The data we have
|
| 53 |
+
- The algorithm we choose
|
| 54 |
+
""")
|
| 55 |
+
|
| 56 |
+
# What is needed to train
|
| 57 |
+
st.markdown("## 🧠 What does this model need to learn?")
|
| 58 |
+
st.markdown("""
|
| 59 |
+
Only two things:
|
| 60 |
+
1. **Data** – this is like a textbook full of examples
|
| 61 |
+
2. **Algorithm** – the way the model reads and understands the data
|
| 62 |
+
|
| 63 |
+
If the model is not learning properly, and we can’t fix the data, we usually try switching to a better algorithm.
|
| 64 |
+
""")
|
| 65 |
+
|
| 66 |
+
# Importance of preprocessing
|
| 67 |
+
st.markdown("## 🧹 Why does Preprocessing Matter?")
|
| 68 |
+
st.markdown("""
|
| 69 |
+
Think of this like giving instructions to your student.
|
| 70 |
+
If you explain in a confusing way, they won’t understand.
|
| 71 |
+
That’s what happens when we **don’t preprocess the data properly**.
|
| 72 |
+
|
| 73 |
+
Good learning happens when:
|
| 74 |
+
- Data is cleaned and clear
|
| 75 |
+
- The algorithm matches the task
|
| 76 |
+
""")
|
| 77 |
+
|
| 78 |
+
# Choosing algorithm type
|
| 79 |
+
st.markdown("## 🤔 Picking the Right Learning Style")
|
| 80 |
+
st.markdown("""
|
| 81 |
+
Before training, we first decide **how the machine should learn**.
|
| 82 |
+
|
| 83 |
+
We pick from 4 main types:
|
| 84 |
+
- **Supervised** – learning from labeled data (like question + answer)
|
| 85 |
+
- **Unsupervised** – learning without answers (just explore)
|
| 86 |
+
- **Semi-supervised** – mix of both
|
| 87 |
+
- **Reinforcement** – learn by doing (like in games)
|
| 88 |
+
|
| 89 |
+
Most of the time, we start with **Supervised Learning**.
|
| 90 |
+
""")
|
| 91 |
+
|
| 92 |
+
# Inside Supervised
|
| 93 |
+
st.markdown("## 🧭 Inside Supervised Learning – Classification vs Regression")
|
| 94 |
+
st.markdown("""
|
| 95 |
+
Now, if you’re using supervised learning, you still need to choose:
|
| 96 |
+
- **Classification** if your answer is a category (like “Spam” or “Not Spam”)
|
| 97 |
+
- **Regression** if your answer is a number (like “House Price = $250,000”)
|
| 98 |
+
|
| 99 |
+
Choose based on your problem.
|
| 100 |
+
""")
|
| 101 |
+
|
| 102 |
+
# Data Representation
|
| 103 |
+
st.markdown("## 🧾 How Do We Represent Data to the Model?")
|
| 104 |
+
st.markdown("""
|
| 105 |
+
We write the data in a format the machine understands.
|
| 106 |
+
|
| 107 |
+
It usually looks like this:
|
| 108 |
+
|
| 109 |
+
**D = {(xi, yi)}**
|
| 110 |
+
|
| 111 |
+
- **xi** is the input (like sepal length, petal width)
|
| 112 |
+
- **yi** is the output (like species of flower)
|
| 113 |
+
|
| 114 |
+
If yi is a category → it’s **classification**
|
| 115 |
+
If yi is a number → it’s **regression**
|
| 116 |
+
""")
|
| 117 |
+
|
| 118 |
+
# Preparing data
|
| 119 |
+
st.markdown("## 📋 Preparing Data Before Training")
|
| 120 |
+
st.markdown("""
|
| 121 |
+
Let’s say we already have cleaned, tabular data. Here’s what we do:
|
| 122 |
+
|
| 123 |
+
- First, find out the **features** (inputs) and the **target** (output).
|
| 124 |
+
- For example, in the Iris dataset:
|
| 125 |
+
- Features = sepal length, petal length, etc.
|
| 126 |
+
- Target = species of flower
|
| 127 |
+
""")
|
| 128 |
+
|
| 129 |
+
# Train-test split
|
| 130 |
+
st.markdown("## ✂️ Splitting the Data")
|
| 131 |
+
st.markdown("""
|
| 132 |
+
We don’t train on all data.
|
| 133 |
+
We split it into:
|
| 134 |
+
- **Training Set** – the data we use to teach the model
|
| 135 |
+
- **Testing Set** – the data we use to check how well the model learned
|
| 136 |
+
|
| 137 |
+
This is like:
|
| 138 |
+
- Studying from textbooks (training)
|
| 139 |
+
- Writing a test paper (testing)
|
| 140 |
+
|
| 141 |
+
We usually split in ratios like 80:20 or 70:30.
|
| 142 |
+
And remember:
|
| 143 |
+
- No overlap between training and testing data
|
| 144 |
+
- Each data point should have equal chance to be in either group
|
| 145 |
+
""")
|
| 146 |
+
|
| 147 |
+
# Naming convention
|
| 148 |
+
st.markdown("## 🧾 Naming Things After Split")
|
| 149 |
+
st.markdown("""
|
| 150 |
+
We usually use:
|
| 151 |
+
|
| 152 |
+
- `X_train`, `y_train` → features and labels for training
|
| 153 |
+
- `X_test`, `y_test` → features and labels for testing
|
| 154 |
+
""")
|
| 155 |
+
|
| 156 |
+
# Closing Note
|
| 157 |
+
st.success("🎯 That’s it! You’ve just learned the entire background of how machines get trained. In the next part, we’ll see it in action with a real model.")
|