Implement a majority class classifier that predicts the most frequent label in the training data for all test samples.
The majority classifier is the simplest possible baseline model in machine learning. Despite its simplicity, it provides a crucial performance benchmark that more sophisticated models should exceed. It's particularly useful for understanding dataset characteristics and class imbalance.
y_train: array-like - Training labels (integers)X_test: array-like - Test features (any shape, ignored for prediction)Input: y_train=[0,1,1,1,0], X_test=[10,20,30]
Output: [1,1,1]
Input: y_train=[2,2,2,1,0], X_test=[5,6]
Output: [2,2]
Use np.unique() with return_counts=True to find class frequencies.
Use np.argmax() to find the index of the most frequent class.
Use np.full() to create an array filled with the majority class.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Implement a majority class classifier that predicts the most frequent label in the training data for all test samples.
The majority classifier is the simplest possible baseline model in machine learning. Despite its simplicity, it provides a crucial performance benchmark that more sophisticated models should exceed. It's particularly useful for understanding dataset characteristics and class imbalance.
y_train: array-like - Training labels (integers)X_test: array-like - Test features (any shape, ignored for prediction)Input: y_train=[0,1,1,1,0], X_test=[10,20,30]
Output: [1,1,1]
Input: y_train=[2,2,2,1,0], X_test=[5,6]
Output: [2,2]
Use np.unique() with return_counts=True to find class frequencies.
Use np.argmax() to find the index of the most frequent class.
Use np.full() to create an array filled with the majority class.
Sign in to take notes on this problem
Accepts: array
Accepts: array