The main goal of linear regression is to find the best straight line that predicts the value of one variable based on another variable.
Click to reveal answer
beginner
What do the slope and intercept represent in a linear regression line?
The slope shows how much the predicted value changes when the input changes by one unit. The intercept is the predicted value when the input is zero.
Click to reveal answer
beginner
Which Python library is commonly used to perform linear regression?
The scikit-learn library is commonly used to perform linear regression in Python.
Click to reveal answer
intermediate
What does the R-squared value tell us in linear regression?
R-squared tells us how well the line fits the data. It shows the percentage of variation in the output explained by the input.
Click to reveal answer
beginner
What is the formula of a simple linear regression line?
The formula is: y = b0 + b1 * x, where y is the predicted value, b0 is the intercept, b1 is the slope, and x is the input variable.
Click to reveal answer
What does the slope in a linear regression line represent?
ATotal variation in data
BPredicted value when input is zero
CChange in predicted value for one unit change in input
DError between predicted and actual values
✗ Incorrect
The slope shows how much the predicted value changes when the input changes by one unit.
Which Python library is commonly used for linear regression?
ANumPy
BPandas
CMatplotlib
Dscikit-learn
✗ Incorrect
Scikit-learn provides easy tools to perform linear regression.
What does an R-squared value close to 1 indicate?
APoor fit of the model
BGood fit of the model
CNo relationship between variables
DModel is overfitting
✗ Incorrect
An R-squared close to 1 means the model explains most of the variation in the data.
In the formula y = b0 + b1 * x, what is b0?
AIntercept
BSlope
CInput variable
DPredicted value
✗ Incorrect
b0 is the intercept, the predicted value when x is zero.
What is the purpose of linear regression?
ATo find a line that predicts one variable from another
BTo reduce data dimensions
CTo cluster similar data points
DTo classify data into groups
✗ Incorrect
Linear regression finds a line to predict one variable based on another.
Explain in your own words what linear regression does and why it is useful.
Think about how you might guess someone's height from their age.
You got /3 concepts.
Describe the meaning of slope and intercept in a linear regression line.
Imagine a hill: slope is steepness, intercept is where it starts.
You got /3 concepts.
Practice
(1/5)
1. What is the main goal of linear regression in data analysis?
easy
A. To find a straight line that best fits the data points
B. To group data points into clusters
C. To calculate the average of all data points
D. To sort data points in ascending order
Solution
Step 1: Understand the purpose of linear regression
Linear regression aims to find a straight line that best represents the relationship between two variables.
Step 2: Compare options with the goal
Only To find a straight line that best fits the data points describes finding a straight line that fits data points, which matches the goal of linear regression.
Final Answer:
To find a straight line that best fits the data points -> Option A
Quick Check:
Linear regression = best fit line [OK]
Hint: Linear regression fits a line to data points [OK]
Common Mistakes:
Confusing regression with clustering
Thinking regression sorts or averages data
Mixing up regression with classification
2. Which of the following is the correct way to import the LinearRegression class from scikit-learn in Python?
easy
A. from sklearn.linear_model import LinearRegression
B. import LinearRegression from sklearn.linear_model
C. from sklearn import LinearRegression
D. import linear_model.LinearRegression
Solution
Step 1: Recall correct import syntax in Python
Python uses 'from module import class' to import specific classes.
Step 2: Match with scikit-learn syntax
Scikit-learn's LinearRegression is in sklearn.linear_model, so the correct import is 'from sklearn.linear_model import LinearRegression'.
Final Answer:
from sklearn.linear_model import LinearRegression -> Option A
Quick Check:
Correct import = from sklearn.linear_model import LinearRegression [OK]
Hint: Use 'from module import class' for specific imports [OK]
Common Mistakes:
Using wrong import order
Trying to import class directly from sklearn
Using incorrect module names
3. What will be the output of this Python code using scikit-learn's LinearRegression?
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array([[1], [2], [3], [4]])
y = np.array([2, 4, 6, 8])
model = LinearRegression()
model.fit(X, y)
pred = model.predict([[5]])
print(round(pred[0], 1))
medium
A. 12.0
B. 9.0
C. 10.0
D. 8.0
Solution
Step 1: Understand the data and model fitting
X values are 1 to 4, y values are 2, 4, 6, 8, which is y = 2 * x perfectly.
Step 2: Predict for X=5 using the fitted model
Since y = 2 * x, prediction for 5 is 2 * 5 = 10. The code rounds to 1 decimal place, so output is 10.0.
Final Answer:
10.0 -> Option C
Quick Check:
Prediction = 2 * 5 = 10.0 [OK]
Hint: Check if data fits y=mx+b, then predict easily [OK]
Common Mistakes:
Ignoring rounding in print
Confusing input shape for predict
Assuming wrong slope or intercept
4. Identify the error in this code snippet for fitting a linear regression model:
from sklearn.linear_model import LinearRegression
X = [1, 2, 3, 4]
y = [2, 4, 6, 8]
model = LinearRegression()
model.fit(X, y)
medium
A. LinearRegression cannot be imported from sklearn.linear_model
B. y should be a 2D array, not a list
C. model.fit requires no arguments
D. X should be a 2D array, not a 1D list
Solution
Step 1: Check input shapes for model.fit
LinearRegression expects X as 2D array (samples, features). Here X is 1D list, which causes error.
Step 2: Confirm y shape is acceptable
y can be 1D array/list for target values, so y is fine.
Final Answer:
X should be a 2D array, not a 1D list -> Option D
Quick Check:
X must be 2D for fit() [OK]
Hint: X must be 2D array for sklearn fit() [OK]
Common Mistakes:
Passing 1D X array causes shape error
Thinking y must be 2D
Misunderstanding import statements
5. You have data of house sizes (in square meters) and their prices (in thousands). You want to predict the price of a house with 120 square meters using linear regression. Given these data points:
Which code snippet correctly fits the model and predicts the price for 120 square meters?
hard
A. from sklearn.linear_model import LinearRegression
X = sizes
y = prices
model = LinearRegression()
model.fit(X, y)
pred = model.predict([120])
print(pred)
B. from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array(sizes).reshape(-1,1)
y = np.array(prices)
model = LinearRegression()
model.fit(X, y)
pred = model.predict([[120]])
print(round(pred[0], 2))
C. import LinearRegression
X = sizes
model = LinearRegression()
model.fit(X, prices)
pred = model.predict(120)
print(pred)
D. from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array(sizes)
y = np.array(prices)
model = LinearRegression()
model.fit(X, y)
pred = model.predict(np.array([120]))
print(pred)
Solution
Step 1: Prepare data in correct shape for fitting
LinearRegression requires X as 2D array, so sizes must be reshaped with .reshape(-1,1).
Step 2: Fit model and predict correctly
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array(sizes).reshape(-1,1)
y = np.array(prices)
model = LinearRegression()
model.fit(X, y)
pred = model.predict([[120]])
print(round(pred[0], 2)) reshapes X, fits model, predicts with [[120]] (2D), and rounds output, which is correct usage.
Final Answer:
from sklearn.linear_model import LinearRegression
import numpy as np
X = np.array(sizes).reshape(-1,1)
y = np.array(prices)
model = LinearRegression()
model.fit(X, y)
pred = model.predict([[120]])
print(round(pred[0], 2)) -> Option B
Quick Check:
Reshape X and predict with 2D input [OK]
Hint: Always reshape X to 2D before fitting and predicting [OK]
Common Mistakes:
Not reshaping X to 2D array
Passing 1D array to predict
Incorrect import or usage of LinearRegression
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.