Sklearn OneVsRestClassifier - Training a Model with an OvR Strategy
Python
1| from sklearn.ensemble import RandomForestClassifier 2| from sklearn.multiclass import OneVsRestClassifier 3| 4| # Step 1: Initialise estimator 5| estimator = RandomForestClassifier(n_estimators=10, 6| max_depth=None, 7| class_weight='balanced', 8| n_jobs=-1, 9| random_state=101) 10| 11| # Step 2: Pass estimator to one vs rest classifier and fit 12| model = OneVsRestClassifier(estimator=estimator).fit(X_train, y_train) 13| 14| # Step 3: Use model to make predictions for X_test 15| y_pred = model.predict(X_test)
142
127
122
115