0
0
ML Pythonprogramming~10 mins

Feature importance in regression in ML Python - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the correct model for linear regression.

ML Python
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
ALinearRegression
BRandomForestRegressor
CLogisticRegression
DKNeighborsRegressor
Attempts:
3 left
2fill in blank
medium

Complete the code to fit the linear regression model on features X and target y.

ML Python
model = LinearRegression()
model.[1](X, y)
Drag options to blanks, or click blank then click option'
Atransform
Bpredict
Cfit
Dscore
Attempts:
3 left
3fill in blank
hard

Fix the error in accessing the feature importance from a linear regression model.

ML Python
importance = model.[1]
Drag options to blanks, or click blank then click option'
Acoef_
Bfeature_coef_
Cimportance_
Dfeature_importances_
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a dictionary mapping feature names to their importance values.

ML Python
feature_importance = { [1]: [2] for [1], [2] in zip(feature_names, importance) }
Drag options to blanks, or click blank then click option'
Aname
Bimportance
Ccoef_
Dvalue
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to print the feature importance sorted by absolute value descending.

ML Python
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}")
Drag options to blanks, or click blank then click option'
A[1]
BTrue
CFalse
D[0]
Attempts:
3 left