You have learned the pieces — now see how they connect into the end-to-end workflow every data scientist follows.
Save
Complete lesson & earn 250 PX
EXERCISE
1You have learned the pieces — now see how they snap together into the workflow that every data scientist follows on every project.
Save
EXERCISE
2Linear regression, polynomial regression, multiple regression, decision trees — when do you use which?
Save
EXERCISE
3You now have a complete beginner's toolkit for machine learning — here is your inventory and the map forward.
Save
Building an ML model is like building a house. You do not just start hammering — you plan, lay the foundation, build the structure, and inspect before anyone moves in. The ML pipeline has the same disciplined order.
The 6-step ML pipeline:
1. COLLECT → Gather and load your data
2. EXPLORE → Visualise, check types, find outliers
3. PREPARE → Scale features, handle missing values, encode categories
4. MODEL → Choose and train an algorithm
5. EVALUATE → Train/test split, check R² or accuracy
6. PREDICT → Deploy the model on new data
import numpy
import pandas as pd
from sklearn import linear_model
from sklearn.preprocessing import StandardScaler
from sklearn.metrics import r2_score
# Step 1: COLLECT
df = pd.read_csv("cars2.csv")
# Step 2: EXPLORE
print(df.describe())
# Output: summary statistics for all columns
# Step 3: PREPARE
X = df[["Weight", "Volume"]]
y = df["CO2"]
scaler = StandardScaler()
X_scaled = scaler.fit_transform(X)
# Step 4: MODEL
model = linear_model.LinearRegression()
model.fit(X_scaled, y)
# Step 5: EVALUATE
predictions = model.predict(X_scaled)
print(f"R²: {round(r2_score(y, predictions), 4)}")
# Output: R²: 0.7753
# Step 6: PREDICT
new_car = scaler.transform([[2300, 1.3]])
print(f"Predicted CO2: {round(model.predict(new_car)[0], 2)} g/km")
# Output: Predicted CO2: 107.21 g/km
> 💡 Key Insight: The pipeline is not a one-way street — it is a loop. If evaluation shows poor results, you go back: try different (step 2), different scaling (step 3), or a different algorithm (step 4). Real ML is iterative, not linear.
Algorithms are like tools in a toolbox. A hammer is perfect for nails but terrible for screws. Choosing the right ML algorithm starts with understanding your data and your goal.
The algorithm decision guide:
| Question | Answer | Algorithm |
|---|---|---|
| Is the relationship a straight line? | Yes | |
| Is the relationship a curve? | Yes | Polynomial Regression |
| Do you have multiple input variables? | Yes | Multiple Regression |
| Is the output a category (yes/no)? | Yes | |
| Are you unsure? | — | Try all and compare R² |
# Quick comparison workflow
import numpy
from scipy import stats
from sklearn.metrics import r2_score
x = numpy.array([1,2,3,5,6,7,8,9,10,12,13,14,15,16,18,19,21,22])
y = numpy.array([100,90,80,60,60,55,60,65,70,70,75,76,78,79,90,99,99,100])
# Try linear
slope, intercept, r, p, std_err = stats.linregress(x, y)
linear_r2 = r ** 2
print(f"Linear R²: {round(linear_r2, 4)}")
# Output: Linear R²: 0.0155
# Try polynomial (degree 3)
poly_model = numpy.poly1d(numpy.polyfit(x, y, 3))
poly_r2 = r2_score(y, poly_model(x))
print(f"Polynomial R²: {round(poly_r2, 4)}")
# Output: Polynomial R²: 0.9433
# Winner: polynomial regression (R² = 0.94 vs 0.02)
> 💡 Key Insight: There is no single "best" algorithm. The best algorithm is the one that fits YOUR data best while being simple enough to generalise. This principle is called Occam''s Razor in ML: among models with similar performance, always prefer the simpler one. It will be more robust and easier to maintain.
You have gone from "what is ?" to building, evaluating, and deploying regression models and decision trees. That is not a small thing. Here is everything you now know — and where each skill fits in the bigger picture.
Your toolkit inventory:
| Skill | Python Tool | When to Use |
|---|---|---|
| Mean, Median, Mode | numpy.mean(), numpy.median(), scipy.stats.mode() | First look at any data set |
| Std Dev & Variance | numpy.std(), numpy.var() | Measuring spread and reliability |
| Percentiles | numpy.percentile() | Outlier detection, binning |
| Histograms | matplotlib.pyplot.hist() | See distribution shape |
| Scatter Plots | matplotlib.pyplot.scatter() | See relationships between variables |
| Linear Regression | scipy.stats.linregress() | Straight-line relationships |
| Polynomial Regression | numpy.polyfit() + numpy.poly1d() | Curved relationships |
| Multiple Regression | sklearn.linear_model.LinearRegression() | Multiple input variables |
| Feature Scaling | sklearn.preprocessing.StandardScaler() | Before feeding data to models |
| Train/Test Split | Manual split or sklearn.model_selection.train_test_split() | Evaluating model honestly |
| Decision Trees | sklearn.tree.DecisionTreeClassifier() | problems |
The learning path ahead:
# Where to go next:
next_topics = [
"K-Nearest Neighbours (KNN)", # Classification
"Logistic Regression", # Binary classification
"Random Forests", # Better decision trees
"Neural Networks", # Deep learning
"Cross-Validation", # Better than single train/test
"Hyperparameter Tuning", # Optimising model settings
]
for i, topic in enumerate(next_topics, 1):
print(f"{i}. {topic}")
# Output:
# 1. K-Nearest Neighbours (KNN)
# 2. Logistic Regression
# 3. Random Forests
# 4. Neural Networks
# 5. Cross-Validation
# 6. Hyperparameter Tuning
> 💡 Key Insight: The gap between "course learner" and "ML practitioner" is not more algorithms — it is practice on messy real-world data. Kaggle competitions, personal projects, and work datasets will teach you more than any course. You now have the foundations. Go build things that matter.
The ML workflow is: collect data, explore and visualise, choose a model, train, evaluate, and predict. Every project follows this loop.