TensorTonicTensorTonic
Problems
Study PlansProjectsNewInterviewPricingFeedback
Problems
Loading...
1 / 1

Implement Majority Class Classifier

Classic ML
Easy

Build a baseline classifier that predicts the most frequent training label for every test sample. If multiple labels have the same maximum frequency, choose the one that appears first in y_train. Features in X_test determine only how many predictions to return. Return a one-dimensional NumPy integer array.

Loading visualization...

Examples

Input: y_train = [0, 1, 1, 1, 0], X_test = [10, 20, 30]

Output: [1, 1, 1]

Explanation: Label 1 occurs three times, so it is predicted for all three samples.

Input: y_train = [2, 2, 2, 1, 0], X_test = [5, 6]

Output: [2, 2]

Hint 1

Use np.unique(y_train, return_index=True, return_counts=True) to obtain counts and first positions.

Hint 2

Among labels with the maximum count, select the smallest recorded first position.

Requirements

  • Count the occurrences of every training label
  • Resolve frequency ties by first appearance in y_train
  • Return one prediction per test sample
  • Return a one-dimensional NumPy integer array

Constraints

  • y_train contains at least one integer label
  • X_test may contain scalar or vector samples
  • Use NumPy only
Try Similar Problems
Random Forest VoteGaussian Naive BayesNaive Bayes BernoulliDecision Tree SplitClassification Metrics

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.
PrevNext

Implement Majority Class Classifier

Classic ML
Easy

Build a baseline classifier that predicts the most frequent training label for every test sample. If multiple labels have the same maximum frequency, choose the one that appears first in y_train. Features in X_test determine only how many predictions to return. Return a one-dimensional NumPy integer array.

Loading visualization...

Examples

Input: y_train = [0, 1, 1, 1, 0], X_test = [10, 20, 30]

Output: [1, 1, 1]

Explanation: Label 1 occurs three times, so it is predicted for all three samples.

Input: y_train = [2, 2, 2, 1, 0], X_test = [5, 6]

Output: [2, 2]

Hint 1

Use np.unique(y_train, return_index=True, return_counts=True) to obtain counts and first positions.

Hint 2

Among labels with the maximum count, select the smallest recorded first position.

Requirements

  • Count the occurrences of every training label
  • Resolve frequency ties by first appearance in y_train
  • Return one prediction per test sample
  • Return a one-dimensional NumPy integer array

Constraints

  • y_train contains at least one integer label
  • X_test may contain scalar or vector samples
  • Use NumPy only
Try Similar Problems
Random Forest VoteGaussian Naive BayesNaive Bayes BernoulliDecision Tree SplitClassification Metrics

Sign in to take notes on this problem

Case 1
Case 2

Accepts: array

Accepts: array

You must run your code first.