0
0
Data Analysis Pythondata~10 mins

Linear regression basics in Data Analysis 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 linear regression model from scikit-learn.

Data Analysis Python
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
ADecisionTreeRegressor
BLinearRegression
CLogisticRegression
DKNeighborsClassifier
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing LogisticRegression which is for classification, not regression.
Using DecisionTreeRegressor which is a different model type.
2fill in blank
medium

Complete the code to create a linear regression model object.

Data Analysis Python
model = [1]()
Drag options to blanks, or click blank then click option'
ALinearRegression
BLogisticRegression
CRandomForestRegressor
DKMeans
Attempts:
3 left
💡 Hint
Common Mistakes
Using LogisticRegression which is for classification.
Using clustering models like KMeans.
3fill in blank
hard

Fix the error in the code to fit the model with features X and target y.

Data Analysis Python
model.fit([1], y)
Drag options to blanks, or click blank then click option'
Ay
Bfit
CX
Dmodel
Attempts:
3 left
💡 Hint
Common Mistakes
Passing the target variable y as the first argument.
Passing the model object itself.
4fill in blank
hard

Fill both blanks to predict target values using the model and features X.

Data Analysis Python
predictions = model.[1]([2])
Drag options to blanks, or click blank then click option'
Apredict
BX
Cfit
Dscore
Attempts:
3 left
💡 Hint
Common Mistakes
Using fit instead of predict.
Passing the model object instead of features.
5fill in blank
hard

Fill all three blanks to create a dictionary of feature names and their coefficients from the model.

Data Analysis Python
coef_dict = { [1]: [2] for [3], coef in zip(feature_names, model.coef_) }
Drag options to blanks, or click blank then click option'
Aname
Bcoef
Dfeature
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong variable names that don't match the loop variables.
Mixing up keys and values in the dictionary comprehension.