from sklearn.model_selection import KFold
from sklearn.model_selection import cross_val_score
from sklearn.datasets import make_classification
from deslib.dcs.ola import OLA
X, y = make_classification(n_samples=200, n_features=5, n_informative=4, n_redundant=1, n_repeated=0, n_classes=3, shuffle=True, random_state=1)
model = OLA()
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
scores = cross_val_score(model, X, y, cv=kfold, scoring="accuracy")
print("Accuracy: ", scores.mean())
Here, we are first creating two ndarrays X and y using the ake_classification() function. X contains 5 features with 44 informative features and one redundant feature.
X, y = make_classification(n_samples=200, n_features=5, n_informative=4, n_redundant=1, n_repeated=0, n_classes=3, shuffle=True, random_state=1)
We are shuffling the features and the samples while creating the ndarrays. And the random_state argument is used to initialize the pseudo-random number generator that is used for randomization.
model = OLA()
Now, we are initializing the model using the OLA class. Please note that if no argument is provided, then the pool of classifiers is a bagging classifier.
kfold = KFold(n_splits=10, shuffle=True, random_state=1)
Now, we are using k-fold cross-validation with 10 splits. We are shuffling the data before splitting, and the random_state argument is used to initialize the pseudo-random number generator that is used for randomization.
scores = cross_val_score(model, X, y, cv=kfold, scoring="accuracy")
print("Accuracy: ", scores.mean())
As discussed, in DCS OLA, the best-performing classifier is used for prediction. We can use the cross-val_score() function to estimate the performance of the model. We are using the accuracy score here (What is the accuracy score in machine learning?)
The average accuracy score of the model will be:
Accuracy: 0.7450000000000001








































0 Comments