Thuta Learning
BasicData & Databasesintermediate

Your First ML Model

Relax. We'll talk through this in plain words — no textbook voice.

What you'll walk away with

  • Understand Your First ML Model, without any of the intimidation
  • Be able to run scikit-learn code yourself
  • Be able to apply this concept immediately in a real project

Let's think about it this way for a second

Linear Regression is one of the simplest, easiest-to-understand ML algorithms — it finds the linear relationship (a straight line) between a feature (x) and a target (y). scikit-learn's API pattern is consistent across every algorithm — `.fit(X_train, y_train)` (train the model) and `.predict(X_test)` (make predictions) — you'll see this same pattern come up again and again throughout the tutorial, no matter which algorithm you're using.

Let's connect it to a real scenario

To predict house price (y) from house size (X) — writing `from sklearn.linear_model import LinearRegression; model = LinearRegression(); model.fit(X_train, y_train)` trains the model, and `predictions = model.predict(X_test)` predicts the price for the test data — running `model.score(X_test, y_test)` immediately shows you the model's accuracy (R² score).

Let's look at it together

python
from sklearn.linear_model import LinearRegression

model = LinearRegression()
model.fit(X_train, y_train)

predictions = model.predict(X_test)
print(predictions[:5])

accuracy = model.score(X_test, y_test)
print(f"R^2 score: {accuracy:.2f}")
You should see
[245000. 312000. 198000. 410000. 275000.]
R^2 score: 0.87

5-minute try-it

Create your own sample dataset (house size vs. price), then train/predict/score a Linear Regression model — confirm you get an R² score back.

A quick word of caution

Don't treat a single R² score as the final word on whether a Linear Regression model is 'good' or 'bad' — you should look at multiple evaluation metrics together (covered in the Intermediate chapter).

Easy traps

  • Trying to call `.predict()` directly without remembering to run `.fit()` first — this gives you a 'model not fitted' error
  • Not getting suspicious when you see an R² score of 0.99+ (almost perfect) and just assuming 'the model is amazing' — that can be a warning sign of overfitting or data leakage

Now try it yourself

Create your own sample dataset (house size vs. price), then train/predict/score a Linear Regression model — confirm you get an R² score back.

You'll know it worked when: [245000. 312000. 198000. 410000. 275000.] R^2 score: 0.87

Your First ML Model | Thuta Learning