Bird
Raised Fist0
ML Pythonml~20 mins

Multiple linear regression in ML Python - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Multiple Linear Regression Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the role of coefficients in multiple linear regression

In multiple linear regression, what does each coefficient represent?

AThe total variance explained by all features combined.
BThe average value of the target variable across all data points.
CThe change in the target variable for a one-unit change in the corresponding feature, holding other features constant.
DThe probability that the model predictions are correct.
Attempts:
2 left
💡 Hint

Think about how one feature affects the output when others do not change.

❓ Predict Output
intermediate
2:00remaining
Output of prediction with given coefficients and input

Given a multiple linear regression model with coefficients [2, -1, 0.5] and intercept 3, what is the predicted value for input features [4, 2, 6]?

ML Python
coefficients = [2, -1, 0.5]
intercept = 3
features = [4, 2, 6]
prediction = intercept + sum(c * f for c, f in zip(coefficients, features))
print(prediction)
A8.0
B12.0
C11.0
D10.0
Attempts:
2 left
💡 Hint

Calculate each product, then add them all plus the intercept.

❓ Hyperparameter
advanced
2:00remaining
Choosing the right regularization for multiple linear regression

You want to reduce overfitting in a multiple linear regression model by adding a penalty on large coefficients. Which regularization method should you choose if you want some coefficients to become exactly zero?

ANo regularization
BL2 regularization (Ridge)
CEarly stopping
DL1 regularization (Lasso)
Attempts:
2 left
💡 Hint

Think about which method can shrink coefficients to zero, effectively selecting features.

❓ Metrics
advanced
2:00remaining
Interpreting R-squared in multiple linear regression

What does an R-squared value of 0.85 indicate about a multiple linear regression model?

A85% of the variance in the target variable is explained by the model's features.
BThe model's predictions are 85% accurate on new data.
CThe model has an 85% chance of making correct predictions.
DThe model's error rate is 15%.
Attempts:
2 left
💡 Hint

R-squared measures how well the model explains the data variance.

🔧 Debug
expert
2:00remaining
Identifying the error in multiple linear regression prediction code

What error will this code raise when predicting with a multiple linear regression model?

import numpy as np
coefficients = np.array([1.5, -2.0, 0.7])
intercept = 0.5
features = np.array([2, 3])
prediction = intercept + np.dot(coefficients, features)
print(prediction)
AValueError due to shape mismatch in np.dot
BNo error, prints a valid prediction
CTypeError because coefficients and features are different types
DNameError because np is not imported
Attempts:
2 left
💡 Hint

Check if the number of features matches the number of coefficients.

Practice

(1/5)
1. What does multiple linear regression do in simple terms?
easy
A. It predicts a result using several input features combined.
B. It groups data into clusters based on similarity.
C. It reduces the number of features by combining them.
D. It finds the shortest path between two points.

Solution

  1. Step 1: Understand the purpose of multiple linear regression

    Multiple linear regression uses multiple inputs to predict a single output by finding the best weights for each input.
  2. Step 2: Compare options with this understanding

    Only It predicts a result using several input features combined. correctly describes predicting a result using several inputs combined.
  3. Final Answer:

    It predicts a result using several input features combined. -> Option A
  4. Quick Check:

    Multiple inputs predict output = A [OK]
Hint: Remember: multiple inputs, one output prediction [OK]
Common Mistakes:
  • Confusing regression with clustering
  • Thinking it reduces features instead of weighting them
  • Mixing it up with pathfinding algorithms
2. Which of the following is the correct formula for multiple linear regression prediction?
easy
A. y = w0 + w1*x1 + w2*x2 + ... + wn*xn
B. y = w0 * x1 + w1 * x2 + ... + wn * xn
C. y = w0 / x1 + w1 / x2 + ... + wn / xn
D. y = w0 - w1*x1 - w2*x2 - ... - wn*xn

Solution

  1. Step 1: Recall the multiple linear regression formula

    The prediction is a sum of a bias term plus each input multiplied by its weight: y = w0 + w1*x1 + w2*x2 + ... + wn*xn.
  2. Step 2: Check each option against the formula

    Only y = w0 + w1*x1 + w2*x2 + ... + wn*xn matches the correct formula with addition and multiplication.
  3. Final Answer:

    y = w0 + w1*x1 + w2*x2 + ... + wn*xn -> Option A
  4. Quick Check:

    Sum of weighted inputs plus bias = B [OK]
Hint: Sum weighted inputs plus bias for prediction [OK]
Common Mistakes:
  • Using multiplication instead of addition between terms
  • Dividing weights by inputs
  • Subtracting weights instead of adding
3. Given weights w0=2, w1=3, w2=-1 and inputs x1=4, x2=5, what is the predicted value y using multiple linear regression?
medium
A. 9.5
B. 9
C. 5
D. 10

Solution

  1. Step 1: Apply the formula y = w0 + w1*x1 + w2*x2

    Substitute values: y = 2 + 3*4 + (-1)*5.
  2. Step 2: Calculate the prediction

    Calculate: 3*4 = 12, (-1)*5 = -5, sum = 2 + 12 - 5 = 9.
  3. Step 3: Recheck calculation

    Sum is 9, but 10 says 10, so re-check: 2 + 12 - 5 = 9, so correct answer is 9.
  4. Final Answer:

    9 -> Option B
  5. Quick Check:

    2 + 12 - 5 = 9 [OK]
Hint: Multiply weights by inputs, then add bias [OK]
Common Mistakes:
  • Adding weights instead of multiplying by inputs
  • Forgetting to add bias term w0
  • Mixing up signs of weights
4. Identify the error in this Python code for multiple linear regression prediction:
def predict(x1, x2, w0, w1, w2):
    return w0 + w1 * x1 + w2 + x2

print(predict(3, 4, 1, 2, 3))
medium
A. The print statement syntax is incorrect.
B. The function is missing a return statement.
C. The function parameters are in wrong order.
D. The term w2 + x2 should be w2 * x2 for correct multiplication.

Solution

  1. Step 1: Analyze the formula inside the function

    The formula should multiply each input by its weight: w0 + w1*x1 + w2*x2.
  2. Step 2: Identify the mistake in the code

    The code uses w2 + x2 instead of w2 * x2, which adds instead of multiplies.
  3. Final Answer:

    The term w2 + x2 should be w2 * x2 for correct multiplication. -> Option D
  4. Quick Check:

    Multiplication needed, not addition = A [OK]
Hint: Check all input-weight pairs use multiplication [OK]
Common Mistakes:
  • Using + instead of * between weight and input
  • Forgetting return statement (not here though)
  • Mixing parameter order
  • Incorrect print syntax
5. You have a dataset with features: hours studied (x1), hours slept (x2), and exam score (y). You fit a multiple linear regression model and get weights: w0=5, w1=4, w2=2. What does the weight w1=4 tell you about hours studied?
hard
A. Hours slept affects exam score more than hours studied.
B. Hours studied has no effect on exam score.
C. For each extra hour studied, exam score increases by 4 points, holding sleep constant.
D. Exam score decreases by 4 points for each hour studied.

Solution

  1. Step 1: Understand the meaning of weights in multiple linear regression

    Each weight shows how much the output changes when that input increases by one unit, keeping others fixed.
  2. Step 2: Interpret w1=4 for hours studied

    A weight of 4 means exam score increases by 4 points for each additional hour studied, assuming hours slept stays the same.
  3. Final Answer:

    For each extra hour studied, exam score increases by 4 points, holding sleep constant. -> Option C
  4. Quick Check:

    Weight shows effect per unit input = D [OK]
Hint: Weight = change in output per unit input [OK]
Common Mistakes:
  • Thinking weight means no effect
  • Confusing positive and negative effect
  • Mixing effects of different features
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard