0
0
ML Pythonprogramming~20 mins

Why classification predicts categories in ML Python - Challenge Your Understanding

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Classification Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Why does classification output categories?

Imagine you have a basket of fruits and you want to sort them into apples, oranges, and bananas. Why does a classification model predict categories instead of numbers?

ABecause classification models assign each input to a specific group or label representing a category.
BBecause classification models calculate the average value of the input features.
CBecause classification models predict continuous values like weight or price.
DBecause classification models generate random numbers for each input.
Attempts:
2 left
Predict Output
intermediate
2:00remaining
Output of classification prediction code

What is the output of this code that uses a simple classification model to predict the category of a flower?

ML Python
from sklearn.datasets import load_iris
from sklearn.tree import DecisionTreeClassifier

iris = load_iris()
X, y = iris.data, iris.target
model = DecisionTreeClassifier(random_state=0)
model.fit(X, y)
prediction = model.predict([[5.1, 3.5, 1.4, 0.2]])
print(prediction)
A[3]
B[0]
C[1]
D[2]
Attempts:
2 left
Model Choice
advanced
2:00remaining
Choosing a model for category prediction

You want to build a model that predicts if an email is spam or not (two categories). Which model is best suited for this classification task?

APrincipal Component Analysis (PCA)
BK-Means Clustering
CLinear Regression
DLogistic Regression
Attempts:
2 left
Metrics
advanced
2:00remaining
Which metric measures classification accuracy?

You trained a classification model and want to know how often it predicts the correct category. Which metric should you use?

AAccuracy
BMean Squared Error (MSE)
CR-squared
DRoot Mean Squared Error (RMSE)
Attempts:
2 left
🔧 Debug
expert
2:00remaining
Why does this classification code raise an error?

Consider this code snippet that tries to predict categories but raises an error. What is the cause?

ML Python
from sklearn.tree import DecisionTreeClassifier

model = DecisionTreeClassifier()
model.fit([[1, 2], [3, 4]], [0, 1])
prediction = model.predict([1, 2])
print(prediction)
AThe model was not trained before prediction.
BDecisionTreeClassifier cannot handle numeric inputs.
CThe input to predict should be a 2D array, but [1, 2] is 1D.
DThe labels should be strings, not integers.
Attempts:
2 left