One tree can make a brittle decision from its particular training data. A forest lets independently built trees vote, so patterns they agree on survive while individual tree mistakes can be outvoted. This question combines already-built classification trees; it does not build or traverse them itself.
Implement random_forest_predict(trees, input) by collecting each tree's predictions and taking a separate majority vote for every input row.
trees is a list of compatible fitted tree dictionaries and input has shape (n_samples, n_features).(n_samples,).predict_tree once per tree; do not reimplement traversal.Open one at a time. Each gives away a little more than the last.
Stacking one prediction vector per tree produces rows of tree opinions and columns of opinions about one sample.
For each column, np.unique(..., return_counts=True) supplies sorted labels and vote totals. np.argmax chooses the first maximum.
No results yet
Run your code to check it against the examples, or submit to run every test.