Supervised Learning with Scikit-Learn
Build and evaluate supervised learning models such as linear regression and classification.
Supervised Learning with Scikit-Learn is a free Python Academy lesson on CoddyKit. This is lesson 2 of 6. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Python Academy learning path, and your progress syncs across the web and the CoddyKit app. The Python Academy course includes 6 lessons in total.
Supervised Learning with Scikit-Learn
Supervised learning involves training a model using labeled data to make predictions or classify data points. Scikit-learn is a popular Python library for implementing supervised learning models.
In this lesson, you’ll learn how to build and evaluate supervised learning models using Scikit-learn.

What is Supervised Learning?
Supervised learning uses labeled data, where each input has a corresponding output. The goal is to learn a mapping from inputs to outputs.
Common tasks include:
- Regression: Predicting continuous values, e.g., house prices.
- Classification: Predicting categories, e.g., spam or not spam.
Setting Up Scikit-Learn
Install Scikit-learn using pip:
pip install scikit-learn
Once installed, you can import it and start building models.
Linear Regression
Linear regression is used to predict continuous values. Let’s build a simple linear regression model:
# Example: Linear Regression
from sklearn.linear_model import LinearRegression
# Sample data
X = [[1], [2], [3]]
y = [2, 4, 6]
model = LinearRegression()
model.fit(X, y)
print("Predicted value:", model.predict([[4]]))Logistic Regression
Logistic regression is used for binary classification tasks, such as determining whether an email is spam or not.
# Example: Logistic Regression
from sklearn.linear_model import LogisticRegression
# Sample data
X = [[1], [2], [3]]
y = [0, 0, 1]
model = LogisticRegression()
model.fit(X, y)
print("Predicted class:", model.predict([[1.5]]))Decision Trees
Decision trees are versatile models that can handle both regression and classification tasks. Let’s build a simple decision tree classifier:
# Example: Decision Tree Classifier
from sklearn.tree import DecisionTreeClassifier
# Sample data
X = [[1], [2], [3]]
y = [0, 1, 0]
model = DecisionTreeClassifier()
model.fit(X, y)
print("Predicted class:", model.predict([[2.5]]))Evaluating Models
Scikit-learn provides metrics to evaluate model performance:
- Mean Squared Error (MSE): For regression models.
- Accuracy: For classification models.
# Example: Evaluating a model
from sklearn.metrics import mean_squared_error
# Predictions
y_true = [2, 4, 6]
y_pred = [2.1, 3.9, 5.8]
print("MSE:", mean_squared_error(y_true, y_pred))Train-Test Split
Always split your dataset into training and testing sets to evaluate model performance on unseen data:
# Example: Train-Test Split
from sklearn.model_selection import train_test_split
X = [[1], [2], [3], [4]]
y = [0, 1, 0, 1]
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.25)
print("Training data:", X_train)Common Mistakes in Supervised Learning
Here are some mistakes to avoid:
- Not splitting data into training and testing sets.
- Overfitting the model by using overly complex algorithms.
- Using poorly labeled data for training.
What Did We Learn?
In this lesson, you learned:
- How to build regression and classification models using Scikit-learn.
- How to evaluate model performance using metrics like MSE and accuracy.
- The importance of splitting data into training and testing sets.
- Common mistakes to avoid in supervised learning tasks.
Great job! Let’s move to the next topic.

Learn Python with an AI tutor — free
Write and run real code in your browser, get instant help from a 24/7 AI tutor, and pick up where you left off on the web or in the app.
- Courses
- 76
- Lessons
- 320
Frequently Asked Questions
Is the “Supervised Learning with Scikit-Learn” lesson free?
Yes — the full text of “Supervised Learning with Scikit-Learn” is free to read here on the web. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Python Academy course, upgrade to CoddyKit PRO. The Python Academy course includes 6 lessons in total.
What will I learn in “Supervised Learning with Scikit-Learn”?
Build and evaluate supervised learning models such as linear regression and classification. You practise Python Academy with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Python Academy?
No prior experience is required. Python Academy on CoddyKit is structured for beginners through advanced learners, so you can start here or from the beginning and move at your own pace. This is lesson 2 of 6.
How long does the “Supervised Learning with Scikit-Learn” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Python Academy lesson?
Yes. Every Python Academy lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Introduction to Machine Learning
- Supervised Learning with Scikit-Learn
- Unsupervised Learning
- Feature Engineering and Selection
- Introduction to Neural Networks
- Introduction to TensorFlow and Keras