Is there a way to perform a hyperparameter grid search with Orange?


1 Answer 1


Yes, you can perform a hyperparameter grid search with Orange by using the GridSearchCV class from the sklearn.model_selection module, as Orange itself doesn't provide a built-in method for hyperparameter grid search. Since Orange is built on top of scikit-learn, it is compatible with scikit-learn's tools and models.

import Orange
from sklearn.datasets import load_iris
from sklearn.model_selection import GridSearchCV
from sklearn.tree import DecisionTreeClassifier
from sklearn.pipeline import Pipeline
from sklearn import preprocessing

#load the data and convert it into an Orange table
iris = load_iris()
iris_data = Orange.data.Table(iris.data, iris.target)

#Create a scikit-learn pipeline with the desired preprocessor and estimator
pipeline = Pipeline([
    ('scaler', preprocessing.StandardScaler()),  # Preprocessing (optional)
    ('classifier', DecisionTreeClassifier())  # Your classifier (e.g., Decision Tree)

#define the hyperparameter search grid
param_grid = {
    'scaler': [preprocessing.StandardScaler(), preprocessing.MinMaxScaler()],
    'classifier__criterion': ['gini', 'entropy'],
    'classifier__max_depth': [3, 4, 5, 6]

#create the GridSearchCV object and fit it into data
grid_search = GridSearchCV(pipeline, param_grid, scoring='accuracy', cv=5)
grid_search.fit(iris_data.X, iris_data.Y)

#print the best hyperparameters and corresponding scores
print("Best hyperparameters:", grid_search.best_params_)
print("Best score:", grid_search.best_score_)
Best hyperparameters: {'classifier__criterion': 'gini', 'classifier__max_depth': 4, 'scaler': MinMaxScaler()}
Best score: 0.9666666666666668

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.