Ibnovate Course 2 · The Rising Builders
⏱ 75 minLive session

Session 3 — Your First Prediction

Duration: 75 min · Format: live online

What you'll learn: by the end, you can explain how a model learns a pattern, why we split data into training and test sets, and build and run a real prediction with scikit-learn.

Soft skill focus — Critical thinking

Today you'll also grow Critical thinking. A model that scores well on its own training data can look perfect while having learned nothing — you have to question a good-looking result, not just accept it.

What you'll need


Hook

Think about these questions:

Here's the idea: your brain already sees the pattern. A model is just a program that finds that pattern in data and uses it to predict new cases. Today you'll make a computer predict — not magic, just patterns and math.


Teach — A model learns the pattern, then predicts

Give a model some data points, and it finds the line — the pattern — that fits them. Then it can predict a new value by reading off that line.

Look at this diagram — notice the three parts:

A scatter of points, a model line through them, and a predicted new point

Ask yourself: "If all the dots sat perfectly on one straight line, how confident would the prediction be? What if they were scattered everywhere?" (Answer: a tight line means a strong, reliable pattern; a scattered cloud means a weak one.)

⚠ Watch for: it's tempting to think the model "memorises" the answers. It doesn't store the dots — it learns a general rule (the line) it can apply to inputs it has never seen.


Teach — Train, then test — no cheating

You never test a model on the same data it learned from — that's like handing it the exam answers first. Instead, you split the data into two parts.

Look at this diagram — walk through the split:

Data split into 80% training and 20% test, feeding a model that scores 92% accuracy

Ask yourself: "Why would testing on the training data give a misleadingly high score?" (Answer: the model has already seen those answers, so it can look perfect without having learned a general pattern.)

⚠ Watch for: it's tempting to judge a model by how well it does on data it trained on. Remember the test set — data it has never seen — is the only honest measure.


Activity — Build a real predictor

Open your own Google Colab and build a working predictor, line by line.

Type and run this in Colab:

from sklearn.linear_model import LinearRegression

# our data: hours studied  ->  test score
hours  = [[1], [2], [3], [4], [5]]
scores = [52, 60, 71, 79, 90]

model = LinearRegression()
model.fit(hours, scores)          # 1) learn the pattern

prediction = model.predict([[6]]) # 2) predict for 6 hours
print("Predicted score:", prediction[0])

Watch out for the double-brackets confusion — hours is a list of lists ([[1], [2], …]), and predict also needs [[6]], not [6]. This is the error most people hit.

You just trained a machine learning model in six lines. That .fit() step is the learning.


Check yourself

Try these — then check your answers:

  1. Why do we keep a separate test set? → To check if the model really learned — not just memorised. Testing on the training data would be cheating.
  2. In the code, which line is the "learning" step?model.fit(hours, scores).fit() finds the pattern in the data.
  3. What does higher accuracy mean? → The model is right more often on data it hasn't seen before.

Wrap-up


Tips & extra challenges

from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_absolute_error

# X = features, y = target (use a real dataset with several rows)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=1)

for model in [LinearRegression(), DecisionTreeRegressor()]:
    model.fit(X_train, y_train)
    preds = model.predict(X_test)
    print(type(model).__name__, "error:", mean_absolute_error(y_test, preds))

Remember lower error = better — which model wins on your data? Now change test_size or random_state and see whether the winner changes (your first real experiment).

Vocabulary

Term Meaning
Model A program that learns a pattern to predict
Train / Fit Teaching the model with data (.fit)
Test set Hidden data used to check the model
Feature An input used to predict (e.g. hours)
Accuracy How often the model is right

Resources

Practice set

Practise on your own — extra exercises on models, train/test, .fit()/.predict(), and the double-bracket shape, easy to hard.

1. Vocabulary check: in model.fit(hours, scores), which list is the feature and which is the target? → hours is the feature (input); scores is the target (what we predict).

2. Spot the "learning" line: in a scikit-learn script, which method actually learns the pattern — .fit() or .predict()? → .fit() finds the pattern; .predict() just uses it.

3. Fix the shape bug: this errors — why, and how do you fix it? → scikit-learn needs a list of lists. Fix: model.predict([[7]]), not [7].

model.predict([7])

4. Fix the order bug: why does this crash? → .predict() is called before .fit(); the model hasn't learned yet. Move model.fit(X, y) above the predict line.

model = LinearRegression()
print(model.predict([[3]]))
model.fit(X, y)

5. Predict and read the result: after fitting on the study-hours data, write the line that prints the predicted score for 7 hours as a plain number. → print(model.predict([[7]])[0]) — the [0] pulls the single value out of the result list.

6. Write the split (harder): using train_test_split, split X and y so that 20% is held out for testing, reproducibly. →

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.2, random_state=1)

7. Reasoning (hardest): a classmate reports 100% accuracy but tested on the same rows the model trained on. Is the score trustworthy? → No — the model has already seen those answers, so it looks perfect without proving it learned a general pattern. Test on the held-out set instead.

Going deeper (optional)

If you're flying through this, open the black box: a LinearRegression model is just learning the line score = slope × hours + intercept. After fitting, you can read those two numbers straight out of the model:

from sklearn.linear_model import LinearRegression

hours  = [[1], [2], [3], [4], [5]]
scores = [52, 60, 71, 79, 90]

model = LinearRegression()
model.fit(hours, scores)

print("slope:", model.coef_[0])        # points gained per extra hour
print("intercept:", model.intercept_)  # predicted score at 0 hours

Interpret it in plain English: "each extra hour of study adds about coef_ points, starting from intercept_." Then check that slope * 6 + intercept gives the same answer as model.predict([[6]]) — proving the model really is just that line, not magic. This connects .fit() back to the best-fit line you can picture.

Common mistakes & fixes

What's next

Session 4 — What AI Can (and Can't) Do: before going further, the most important lesson of the unit — you'll learn to use this power responsibly and fairly.

Ibnovate · Build · Innovate
Type to search · Esc to close
Welcome back
Sign in to continue building.
Accounts are created by Ibnovate — ask your instructor for your login.
🔒