Linear regression is a way to find a straight line that best fits a set of points. It helps predict one value based on another by drawing a line through the data.
Click to reveal answer
beginner
What does the 'prediction' mean in linear regression?
Prediction means using the line equation to guess the output value for a new input. For example, if the line is y = 2x + 1, and x=3, the prediction is y=7.
Click to reveal answer
beginner
What are the main parts of a linear regression model?
The main parts are the slope (how steep the line is) and the intercept (where the line crosses the y-axis). Together, they form the equation y = slope * x + intercept.
Click to reveal answer
intermediate
How do we measure if a linear regression model is good?
We check how close the predicted points are to the real points. One way is to look at the loss, like mean squared error, which shows the average squared difference between predicted and real values.
Click to reveal answer
beginner
What is the role of training data in linear regression?
Training data is the set of known input and output pairs used to find the best line. The model learns the slope and intercept from this data to make predictions.
Click to reveal answer
What does the slope in a linear regression model represent?
AThe number of data points used
BThe starting point of the line on the x-axis
CThe error between predicted and actual values
DHow much y changes for a change in x
✗ Incorrect
The slope shows how much the output (y) changes when the input (x) changes by one unit.
If the linear regression equation is y = 3x + 2, what is the predicted y when x = 4?
A8
B14
C10
D12
✗ Incorrect
Plug x=4 into y=3*4+2 = 12+2 = 14.
What is the purpose of training a linear regression model?
ATo calculate the prediction error
BTo test the model on new data
CTo find the best slope and intercept for the data
DTo collect more data points
✗ Incorrect
Training finds the slope and intercept that best fit the training data.
Which metric is commonly used to measure error in linear regression?
AMean Squared Error
BAccuracy
CPrecision
DRecall
✗ Incorrect
Mean Squared Error measures average squared differences between predicted and actual values.
What does the intercept in a linear regression model tell us?
AThe predicted value when x is zero
BThe steepness of the line
CThe error of the model
DThe number of features
✗ Incorrect
The intercept is the value of y when x equals zero.
Explain how a linear regression model makes a prediction for a new input value.
Think about the line equation and how you use it to find y.
You got /5 concepts.
Describe the role of training data in building a linear regression model.
Training data helps the model learn the line that fits best.
You got /4 concepts.
Practice
(1/5)
1. What is the main goal of linear regression in machine learning?
easy
A. To classify data into categories
B. To find a line that best fits the data points
C. To cluster data points into groups
D. To reduce the number of features
Solution
Step 1: Understand linear regression purpose
Linear regression aims to find a straight line that best fits the relationship between input and output data.
Step 2: Compare with other options
Classification, clustering, and feature reduction are different tasks, not the goal of linear regression.
Final Answer:
To find a line that best fits the data points -> Option B
Quick Check:
Linear regression = line fitting [OK]
Hint: Linear regression fits a line, not groups or categories [OK]
Common Mistakes:
Confusing regression with classification
Thinking linear regression clusters data
Believing it reduces features
2. Which of the following is the correct Python syntax to create a simple linear regression model using scikit-learn?
easy
A. model = LinearRegression()
B. model = LinearRegression.fit()
C. model = LinearRegression.fit(X, y)
D. model = LinearRegression(X, y)
Solution
Step 1: Recall model creation syntax
In scikit-learn, you first create the model object with LinearRegression(), without arguments.
Step 2: Understand fitting method
The fit method is called on the model object with data, e.g., model.fit(X, y), not during creation.
Final Answer:
model = LinearRegression() -> Option A
Quick Check:
Model creation uses class name with parentheses [OK]
Hint: Create model with class(), fit separately [OK]
Common Mistakes:
Calling fit during model creation
Passing data to constructor
Using fit as a class method
3. Given the code below, what will be the predicted value for X_new = [[5]]?
from sklearn.linear_model import LinearRegression
X = [[1], [2], [3], [4]]
y = [2, 4, 6, 8]
model = LinearRegression()
model.fit(X, y)
prediction = model.predict([[5]])
print(prediction)
medium
A. [9.]
B. [12.]
C. [8.]
D. [10.]
Solution
Step 1: Understand the training data pattern
The output y doubles the input X: y = 2 * X.
Step 2: Predict for X_new = 5
Using the pattern, prediction = 2 * 5 = 10.
Final Answer:
[10.] -> Option D
Quick Check:
2 x 5 = 10 [OK]
Hint: Check pattern in training data, apply to new input [OK]
Common Mistakes:
Ignoring the pattern and guessing
Using last y value as prediction
Confusing input and output
4. What is wrong with the following code snippet for training 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. X should be a 2D array, not a 1D list
B. y should be a 2D array, not a list
C. LinearRegression() requires parameters in constructor
D. fit() method should be called with no arguments
Solution
Step 1: Check input shape requirements
scikit-learn expects X as a 2D array (list of lists), but X is a 1D list here.
Step 2: Confirm y shape and method usage
y can be 1D list, constructor needs no parameters, fit requires X and y arguments.
Final Answer:
X should be a 2D array, not a 1D list -> Option A
Quick Check:
X must be 2D for fit() [OK]
Hint: X must be 2D array for sklearn fit() [OK]
Common Mistakes:
Passing 1D list for X
Thinking y must be 2D
Adding parameters to LinearRegression()
5. You trained a linear regression model on data where y = 3x + 2. After training, you want to predict the output for x = 10. Which code snippet correctly predicts and prints the result?
hard
A. model.predict([10])\nprint(prediction)
B. prediction = model.predict([10, 2])\nprint(prediction)
C. prediction = model.predict([[10]])\nprint(prediction[0])
D. prediction = model.predict(10)\nprint(prediction)
Solution
Step 1: Understand input shape for prediction
scikit-learn expects a 2D array for prediction input, so [[10]] is correct.
Step 2: Access prediction output correctly
predict returns an array; to print the single value, use prediction[0].
Final Answer:
prediction = model.predict([[10]])
print(prediction[0]) -> Option C
Quick Check:
Input 2D array, print first prediction [OK]
Hint: Use 2D input for predict, print first element [OK]
Common Mistakes:
Passing 1D list or scalar to predict
Printing prediction array directly without indexing
Passing wrong shaped input with extra values
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.