0
0
ML Pythonml~10 mins

Multi-class classification 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 multi-class classification.

ML Python
from sklearn.linear_model import [1]
Drag options to blanks, or click blank then click option'
AKNeighborsClassifier
BLinearRegression
CLogisticRegression
DDecisionTreeRegressor
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing LinearRegression which is for regression tasks.
Using DecisionTreeRegressor which is not a classifier.
2fill in blank
medium

Complete the code to create a logistic regression model for multi-class classification.

ML Python
model = LogisticRegression(multi_class=[1], solver='lbfgs')
Drag options to blanks, or click blank then click option'
A'auto'
B'binary'
C'ovr'
D'multinomial'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'binary' which only works for two classes.
Using 'auto' which defaults to 'ovr' for multi-class.
3fill in blank
hard

Fix the error in the code to correctly fit the multi-class model.

ML Python
model.fit(X_train, [1])
Drag options to blanks, or click blank then click option'
Ay_train
BX_test
Cy_test
DX_train
Attempts:
3 left
💡 Hint
Common Mistakes
Passing X_test or y_test which are for evaluation, not training.
Passing features instead of labels.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps each class to its predicted probability.

ML Python
prob_dict = {cls: [1][i] for i, cls in enumerate([2])}
Drag options to blanks, or click blank then click option'
Aprobs
Bclasses
Cpredictions
Dlabels
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'predictions' which are class labels, not probabilities.
Using 'labels' which is ambiguous.
5fill in blank
hard

Fill all three blanks to compute accuracy score for multi-class classification.

ML Python
from sklearn.metrics import [1]

accuracy = [2]([3], y_pred)
Drag options to blanks, or click blank then click option'
Aaccuracy_score
By_true
Caccuracy
Dprecision_score
Attempts:
3 left
💡 Hint
Common Mistakes
Using precision_score which measures precision, not accuracy.
Swapping true and predicted labels.