1/24
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
The line of code np.random.seed(42) ensures that the sequence of pseudo-random numbers generated is the same every time the code is run.
What does the number 42 represent?
A seed value for the random number generator.
The function np.linspace(0,40,500) is used to generate the independent variable in this code.
What does this function specifically do?
Generates 500 evenly spaced numbers over the closed interval [0, 40].
In the line growth = -0.1 * (temp - 25) ** 2 + 50 + np.random.normal(0,5, size=temp.shape),
what does the term np.random.normal(0,5, size=temp.shape) add to the simulated data?
Random noise following a normal distribution with a mean of 0 and standard deviation of 5.
The operation temp = temp.reshape(-1,1) is a critical step before fitting the scikit-learn model.
What is the primary purpose of this reshaping?
To convert the 1D array into a 2D array with one column, as scikit-learn expects features in this format for a single feature.
The object model = LinearRegression() is instantiated from the sklearn.linear_model module.
What method of this object is called to train the model on the provided data?
model.fit()
After the model is trained, model.predict(temp) is used.
What does this method return?
The predicted growth values for each input temp value, based on the fitted linear model.
The metric calculated as the average of the absolute differences between the actual and predicted values is defined as:
Mean Absolute Error (MAE).
The metric mean_squared_error(growth, growth_pred) calculates the average of the squared differences.
Which of the following metrics is derived by taking the square root of this value to return to the original units of the target variable?
RMSE
The r2_score(growth, growth_pred) calculates a statistical measure that represents:
The proportion of the variance in the dependent variable that is predictable from the independent variable.
In the visualization block, plt.scatter(temp, growth, label='Actual Growth', alpha=0.6) creates a scatter plot. What does the alpha=0.6 parameter control?
The transparency (opacity) of the points.
The command plt.plot(temp, growth_pred, color='red', label='Predicted Growth (Linear Regression)') is used to add the regression line to the plot. What is the key characteristic of this line?
It is the line that minimizes the sum of squared vertical distances (errors) from all data points.
True or False:
The underlying true relationship between temp and growth in the data generation step is linear.
False
True or False:
The LinearRegression model from sklearn.linear_model is used to fit a straight line to the data.
True
True or False:
The code calculates four distinct error/performance metrics: MAE, MSE, RMSE, and R² Score.
True
True or False:
The r2_score can range from -1 to 1.
False
True or False:
In the plotting commands, plt.xlabel('Temperature') and plt.ylabel('Growth') set the labels for the Y-axis and X-axis, respectively.
True
True or False:
The model.fit() function takes the dependent variable (growth) as its first argument and the independent variable (temp) as its second argument.
False
True or False:
The RMSE value will always be greater than or equal to the MAE value for the same set of predictions.
True
True or False:
The command plt.grid(True) adds a horizontal and vertical grid to the plot for easier reading.
True
The library imported as np that provides support for arrays and numerical operations is __.
NumPy
The library imported as plt that is used for creating visualizations is __.
Matplotlib
The specific class imported from sklearn.linear_model to perform the regression is __.
LinearRegression
From sklearn.metrics, the three specific functions imported to calculate error metrics are mean_absolute_error, r2_score, and __.
meansquarederror
The mathematical operation used to calculate rmse from mse in the code is the __.
square root
The figure size for the plot is set to a width of 8 inches and a height of __ inches using plt.figure(figsize=(8, 6)).
6