TensorTonic
Problems
Random Forest Majority Vote
Classic ML
Medium

A Random Forest makes predictions by aggregating the outputs of multiple decision trees. For classification, each tree votes for a class and the final prediction is the class with the most votes (majority vote).

Given the predictions from T decision trees for N samples, compute the majority vote for each sample. Break ties by choosing the smallest class label.

Algorithm

  1. For each sample, count votes from all trees

  2. Select the class with the highest vote count

  3. If multiple classes are tied, pick the smallest class label

Return one integer class label for each sample.

Loading visualization...

Examples

Input: predictions = [[0, 1, 0], [0, 1, 1], [0, 0, 0]]

Output: [0, 1, 0]

Explanation: Votes are counted column by column across the three trees.

Input: predictions = [[0, 1], [1, 0]]

Output: [0, 0]

Hint 1

Build a vote-count dictionary for one sample column at a time.

Hint 2

Find the largest count, then select the smallest label having that count.

Requirements

  • predictions[t][i] is tree t's prediction for sample i
  • Count votes across all trees for each sample
  • Return the class with the most votes (break ties by smallest label)
  • Return a list of integers with length equal to the number of samples

Constraints

  • predictions has at least one tree and one sample
  • All trees predict for the same number of samples
  • Class labels are non-negative integers
  • Return a list of integers
  • Time limit: 300 ms
Try Similar Problems
Compute Gini Impurity for a SplitMediumCompute Entropy for a NodeEasyImplement Majority Class ClassifierEasyDecision Tree Best SplitHardCompute Information Gain for a SplitMediumLogistic Regression Training LoopMediumGaussian Naive BayesHardNaive Bayes Log-Likelihood (Bernoulli)HardBagging ClassifierMediumSoftmax RegressionMediumText ClassificationMediumDecision Tree Classifier (CART)Medium
Scratchpad

Accepts: array

You must run your code first.
Random Forest Majority Vote

Random Forest Majority Vote

Classic ML
Medium

A Random Forest makes predictions by aggregating the outputs of multiple decision trees. For classification, each tree votes for a class and the final prediction is the class with the most votes (majority vote).

Given the predictions from T decision trees for N samples, compute the majority vote for each sample. Break ties by choosing the smallest class label.

Algorithm

  1. For each sample, count votes from all trees

  2. Select the class with the highest vote count

  3. If multiple classes are tied, pick the smallest class label

Return one integer class label for each sample.

Loading visualization...

Examples

Input: predictions = [[0, 1, 0], [0, 1, 1], [0, 0, 0]]

Output: [0, 1, 0]

Explanation: Votes are counted column by column across the three trees.

Input: predictions = [[0, 1], [1, 0]]

Output: [0, 0]

Hint 1

Build a vote-count dictionary for one sample column at a time.

Hint 2

Find the largest count, then select the smallest label having that count.

Requirements

  • predictions[t][i] is tree t's prediction for sample i
  • Count votes across all trees for each sample
  • Return the class with the most votes (break ties by smallest label)
  • Return a list of integers with length equal to the number of samples

Constraints

  • predictions has at least one tree and one sample
  • All trees predict for the same number of samples
  • Class labels are non-negative integers
  • Return a list of integers
  • Time limit: 300 ms
Try Similar Problems
Compute Gini Impurity for a SplitMediumCompute Entropy for a NodeEasyImplement Majority Class ClassifierEasyDecision Tree Best SplitHardCompute Information Gain for a SplitMediumLogistic Regression Training LoopMediumGaussian Naive BayesHardNaive Bayes Log-Likelihood (Bernoulli)HardBagging ClassifierMediumSoftmax RegressionMediumText ClassificationMediumDecision Tree Classifier (CART)Medium
Scratchpad

Accepts: array

You must run your code first.
Problems
Loading...
1 / 1