Complete the code to import the correct model for linear regression.
from sklearn.linear_model import [1]
The LinearRegression class is used to create a linear regression model in scikit-learn.
Complete the code to fit the linear regression model on features X and target y.
model = LinearRegression()
model.[1](X, y)The fit method trains the model using the input features X and target y.
Fix the error in accessing the feature importance from a linear regression model.
importance = model.[1]For linear regression, the coefficients are stored in coef_, which represent feature importance.
Fill both blanks to create a dictionary mapping feature names to their importance values.
feature_importance = { [1]: [2] for [1], [2] in zip(feature_names, importance) }We use name as the key and importance as the value in the dictionary comprehension.
Fill all three blanks to print the feature importance sorted by absolute value descending.
sorted_features = sorted(feature_importance.items(), key=lambda x: abs(x[1]), reverse=[2]) for feature, importance in sorted_features: print(f"Feature: {feature}, Importance: {importance:.2f}")
We sort by the absolute value of the importance which is at index 1 in the tuple, and set reverse to True for descending order.
