Skip to content

Commit 35d3cda

Browse files
ENH: Migrate to model_selection.load_classifier (#37)
* ENH: Remove legacy utilities.check_for_random_state * BUG: Temporarily support dotted paths in base_classifier * REF: Use prepare_param_grid in Utilities * ENH: OrdinalDecomposition uses model_selection.load_classifier * ENH: Remove legacy utilities.load_classifier * TST: Remove dotted paths from Utilities tests * ENH: Drop Utilities._resolve_estimator and dotted path support * REF: Use load_classifier in Utilities, drop _check_params and related test * MNT: Update configuration files * DOC: Update README.md
1 parent d4d25b0 commit 35d3cda

File tree

14 files changed

+51
-339
lines changed

14 files changed

+51
-339
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,18 +90,18 @@ ORCA-python includes sample datasets with pre-partitioned train/test splits usin
9090
},
9191
"configurations": {
9292
"SVM": {
93-
"classifier": "sklearn.svm.SVC",
93+
"classifier": "SVC",
9494
"parameters": {
9595
"C": [0.001, 0.1, 1, 10, 100],
9696
"gamma": [0.1, 1, 10]
9797
}
9898
},
9999
"SVMOP": {
100-
"classifier": "orca_python.classifiers.OrdinalDecomposition",
100+
"classifier": "OrdinalDecomposition",
101101
"parameters": {
102102
"dtype": "ordered_partitions",
103103
"decision_method": "frank_hall",
104-
"base_classifier": "sklearn.svm.SVC",
104+
"base_classifier": "SVC",
105105
"parameters": {
106106
"C": [0.01, 0.1, 1, 10],
107107
"gamma": [0.01, 0.1, 1, 10],
@@ -144,7 +144,7 @@ Controls global experiment parameters.
144144

145145
Defines classifiers and their hyperparameters for GridSearchCV. Each configuration has a name and consists of:
146146

147-
- **`classifier`**: scikit-learn path or built-in ORCA-python classifier
147+
- **`classifier`**: scikit-learn or built-in ORCA-python classifier
148148
- **`parameters`**: hyperparameters for grid search (nested for ensemble methods)
149149

150150
## Running Experiments

orca_python/classifiers/OrdinalDecomposition.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from sklearn.utils._param_validation import StrOptions
66
from sklearn.utils.validation import check_array, check_is_fitted, check_X_y
77

8-
from orca_python.utilities import load_classifier
8+
from orca_python.model_selection import load_classifier
99

1010

1111
class OrdinalDecomposition(BaseEstimator, ClassifierMixin):
@@ -110,7 +110,7 @@ def __init__(
110110
self,
111111
dtype="ordered_partitions",
112112
decision_method="frank_hall",
113-
base_classifier="sklearn.linear_model.LogisticRegression",
113+
base_classifier="LogisticRegression",
114114
parameters={},
115115
):
116116
self.dtype = dtype
@@ -161,7 +161,9 @@ def fit(self, X, y):
161161
# Fitting n_targets - 1 classifiers
162162
for n in range(len(class_labels[0, :])):
163163

164-
estimator = load_classifier(self.base_classifier, self.parameters)
164+
estimator = load_classifier(
165+
self.base_classifier, param_grid=self.parameters
166+
)
165167
estimator.fit(
166168
X[np.where(class_labels[:, n] != 0)],
167169
np.ravel(class_labels[np.where(class_labels[:, n] != 0), n].T),

orca_python/classifiers/tests/test_ordinal_decomposition.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def test_ordinal_decomposition(X, y):
2424
classifier = OrdinalDecomposition(
2525
dtype="ordered_partitions",
2626
decision_method="frank_hall",
27-
base_classifier="sklearn.svm.SVC",
27+
base_classifier="SVC",
2828
parameters={"C": 1.0, "gamma": "scale", "probability": True},
2929
)
3030

orca_python/configurations/full_functionality_test.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
},
1919
"configurations": {
2020
"SVM": {
21-
"classifier": "sklearn.svm.SVC",
21+
"classifier": "SVC",
2222
"parameters": {
2323
"C": [0.001, 0.1, 1, 10, 100],
2424
"gamma": [0.1, 1, 10]
2525
}
2626
},
2727
"SVMOP": {
28-
"classifier": "orca_python.classifiers.OrdinalDecomposition",
28+
"classifier": "OrdinalDecomposition",
2929
"parameters": {
3030
"dtype": "ordered_partitions",
3131
"decision_method": "frank_hall",
32-
"base_classifier": "sklearn.svm.SVC",
32+
"base_classifier": "SVC",
3333
"parameters": {
3434
"C": [0.01, 0.1, 1, 10],
3535
"gamma": [0.01, 0.1, 1, 10],
@@ -38,11 +38,11 @@
3838
}
3939
},
4040
"LR": {
41-
"classifier": "orca_python.classifiers.OrdinalDecomposition",
41+
"classifier": "OrdinalDecomposition",
4242
"parameters": {
4343
"dtype": ["ordered_partitions", "one_vs_next"],
4444
"decision_method": "exponential_loss",
45-
"base_classifier": "sklearn.linear_model.LogisticRegression",
45+
"base_classifier": "LogisticRegression",
4646
"parameters": {
4747
"solver": ["liblinear"],
4848
"C": [0.01, 0.1, 1, 10],
@@ -52,19 +52,19 @@
5252
}
5353
},
5454
"REDSVM": {
55-
"classifier": "orca_python.classifiers.REDSVM",
55+
"classifier": "REDSVM",
5656
"parameters": {
5757
"kernel": "rbf",
5858
"degree": 3,
5959
"gamma": 0.1,
6060
"coef0": 0,
6161
"C": 1,
6262
"tol": 0.001,
63-
"shrinking": 1
63+
"shrinking": true
6464
}
6565
},
6666
"SVOREX": {
67-
"classifier": "orca_python.classifiers.SVOREX",
67+
"classifier": "SVOREX",
6868
"parameters": {
6969
"kernel": "gaussian",
7070
"C": [0.1, 1, 10],

orca_python/configurations/nnop_mae_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"configurations": {
1313
"NNOP-MAE": {
14-
"classifier": "orca_python.classifiers.NNOP",
14+
"classifier": "NNOP",
1515
"parameters": {
1616
"epsilon_init": 0.5,
1717
"n_hidden": [5, 10, 20, 30, 40, 50],

orca_python/configurations/nnop_mze_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"configurations": {
1313
"NNOP-MZE": {
14-
"classifier": "orca_python.classifiers.NNOP",
14+
"classifier": "NNOP",
1515
"parameters": {
1616
"epsilon_init": 0.5,
1717
"n_hidden": [5, 10, 20, 30, 40, 50],

orca_python/configurations/nnpom_mae_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"configurations": {
1313
"NNPOM-MAE": {
14-
"classifier": "orca_python.classifiers.NNPOM",
14+
"classifier": "NNPOM",
1515
"parameters": {
1616
"epsilon_init": 0.5,
1717
"n_hidden": [5, 10, 20, 30, 40, 50],

orca_python/configurations/nnpom_mze_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"configurations": {
1313
"NNPOM-MZE": {
14-
"classifier": "orca_python.classifiers.NNPOM",
14+
"classifier": "NNPOM",
1515
"parameters": {
1616
"epsilon_init": 0.5,
1717
"n_hidden": [5, 10, 20, 30, 40, 50],

orca_python/configurations/redsvm_test.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"configurations": {
1313
"REDSVM": {
14-
"classifier": "orca_python.classifiers.REDSVM",
14+
"classifier": "REDSVM",
1515
"parameters": {
1616
"kernel": "rbf",
1717
"C": [0.001, 0.01, 0.1, 1, 10, 100, 1000],

orca_python/configurations/svmop_test.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
},
1111
"configurations": {
1212
"SVMOP": {
13-
"classifier": "orca_python.classifiers.OrdinalDecomposition",
13+
"classifier": "OrdinalDecomposition",
1414
"parameters": {
1515
"dtype": "ordered_partitions",
1616
"decision_method": "frank_hall",
17-
"base_classifier": "sklearn.svm.SVC",
17+
"base_classifier": "SVC",
1818
"parameters": {
1919
"C": [0.1, 1, 10],
2020
"gamma": [0.1, 1, 10],

0 commit comments

Comments
 (0)