Q1 What is the primary difference between supervised and unsupervised learning?
A) Supervised learning requires more computational power than unsupervised learning
B) Supervised learning uses labeled data while unsupervised learning works with unlabeled data
C) Unsupervised learning can only be used for classification tasks
D) Supervised learning doesn't require any training data
Q2. Explain the concept of overfitting in machine learning. Include in your answer:
- What is overfitting?
- Why does overfitting occur?
- What are two methods to prevent overfitting?
- Provide a simple real-world example to illustrate the concept.
Your Answer here
Q3. COMPLETE THE CODE
Complete the code to implement a simple linear regression model using scikit-learn:
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
import numpy as np
Sample data
X = np.array([[1], [2], [3], [4], [5]])
y = np.array([2, 4, 5, 4, 5])
Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Create a LinearRegression model instance
model = _____
(2) Fit the model on training data
(3) Make predictions on test data
predictions = _____
(4) Calculate the accuracy score (R² score)
from sklearn.metrics import r2_score
score = _____
print(f"Model R² Score: {score}")
🚀 ML Basics - Code Challenge
Complete the Linear Regression Implementation
📋 Instructions
Complete the code below by filling in the blanks marked with _____
- (1) Create a LinearRegression model
- (2) Fit the model with training data
- (3) Make predictions on test data
- (4) Calculate the R² score
💡 Tip: Use scikit-learn methods and functions
💡 Hint
✓ Complete Solution
📚 Key Concepts
Linear Regression is a supervised learning algorithm that models the relationship between
input features (X) and continuous output values (y). The model learns a linear equation: y = mx + b
R² Score (Coefficient of Determination) measures how well predictions fit the actual data. Range: 0 to 1 (1 = perfect fit)
codepen version
https://codepen.io/editor/tannisthamaiti/pen/019db4c2-57be-70bd-a926-1500871cdfa0