#144Regression vs classification outputEasyComputer VisionLinear Regression
Regression vs classification output
Background
Vision models fall into two output families:
- Regression — a continuous value (age, depth, a motion vector). The model output is the answer.
- Classification — a discrete label out of classes. The answer is the index of the highest-scoring class.
Problem statement
Implement vision_task_output(z, task) that returns the right prediction for the task:
task == "regression"→ return the continuous valuezas afloat.task == "classification"→ return the predicted class index (argmaxof the score vectorz) as anint.
Input
z— for regression, a scalar; for classification, an array-like ofKscores/logits.task—"regression"or"classification".
Output
A float (regression) or an int class index (classification).
Examples
Example 1 — regression
Input: z = 3.7, task = "regression"
Output: 3.7
Example 2 — classification
Input: z = [1, 3, 2], task = "classification"
Output: 1
Explanation: index 1 has the largest score.
Constraints
- Regression returns
float(z). - Classification returns
int(argmax(z)).
Notes
- The choice of head (and its loss — squared error for regression, cross-entropy for classification) is what specialises the same backbone to different vision tasks.
Python
Loading...
▶ Run executes the 3 visible sample tests below in your browser. Submit runs the full suite — including hidden tests — on the server for an official verdict.
- •Regression example returns the value
- •Classification reference returns argmax index
- •Sample negative regression value