Skip to content

Commit 3e80845

Browse files
fix classifiers -- bump v0.36.0
1 parent c515ead commit 3e80845

15 files changed

Lines changed: 251 additions & 253 deletions

examples/ridge.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,39 @@
1010

1111
# Single lambda
1212
print("\n\n Single lambda")
13-
model = ns.RidgeRegressor(lambda_=1.0)
13+
model = ns.RidgeRegressor(reg_lambda=1.0)
1414
start = time()
1515
model.fit(X_train, y_train)
1616
predictions = model.predict(X_test)
1717
end = time()
1818
print(f"Time taken: {end - start} seconds")
1919
print(f"coefs: {model.coef_}")
20+
print(f"Test RMSE: {np.sqrt(np.mean((predictions - y_test)**2))}")
21+
2022
# Access criteria
21-
print(f"GCV scores: {model.GCV_}")
22-
print(f"HKB estimate: {model.HKB_}")
23-
print(f"LW estimate: {model.LW_}")
23+
#print(f"GCV scores: {model.GCV_}")
24+
#print(f"HKB estimate: {model.HKB_}")
25+
#print(f"LW estimate: {model.LW_}")
2426

2527

2628
# Multiple lambdas
27-
print("\n\n Multiple lambdas")
28-
model = ns.RidgeRegressor(lambda_=[0.1, 1.0, 10.0])
29-
start = time()
30-
model.fit(X_train, y_train)
31-
end = time()
32-
print(f"Time taken: {end - start} seconds")
33-
predictions = model.predict(X_test) # Returns predictions for each lambda
34-
print(f"coefs: {model.coef_}")
35-
# Access criteria
36-
print(f"GCV scores: {model.GCV_}")
37-
print(f"HKB estimate: {model.HKB_}")
38-
print(f"LW estimate: {model.LW_}")
29+
# print("\n\n Multiple lambdas")
30+
# model = ns.RidgeRegressor(lambda_=[0.1, 1.0, 10.0])
31+
# start = time()
32+
# model.fit(X_train, y_train)
33+
# end = time()
34+
# print(f"Time taken: {end - start} seconds")
35+
# predictions = model.predict(X_test) # Returns predictions for each lambda
36+
# print(f"coefs: {model.coef_}")
37+
# # Access criteria
38+
# print(f"GCV scores: {model.GCV_}")
39+
# print(f"HKB estimate: {model.HKB_}")
40+
# print(f"LW estimate: {model.LW_}")
3941

40-
# Compare coefficients for lambda=1.0
41-
print("\nComparing coefficients for lambda=1.0:")
42-
print("Single lambda coefs:", model.coef_)
43-
print("Multiple lambda coefs (middle column):", model.coef_[:, 1])
42+
# # Compare coefficients for lambda=1.0
43+
# print("\nComparing coefficients for lambda=1.0:")
44+
# print("Single lambda coefs:", model.coef_)
45+
# print("Multiple lambda coefs (middle column):", model.coef_[:, 1])
4446

45-
# With GPU acceleration
46-
#model = RidgeRegressor(lambda_=1.0, backend="gpu")
47+
# # With GPU acceleration
48+
# #model = RidgeRegressor(lambda_=1.0, backend="gpu")

nnetsauce/boosting/adaBoostClassifier.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class AdaBoostClassifier(Boosting, ClassifierMixin):
155155
"""
156156

157157
# construct the object -----
158+
_estimator_type = "classifier"
158159

159160
def __init__(
160161
self,
@@ -461,3 +462,8 @@ def predict_proba(self, X, **kwargs):
461462
sum_ensemble = expit_ensemble_learner.sum(axis=1)
462463

463464
return expit_ensemble_learner / sum_ensemble[:, None]
465+
466+
@property
467+
def _estimator_type(self):
468+
return "classifier"
469+

nnetsauce/custom/customClassifier.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ class CustomClassifier(Custom, ClassifierMixin):
137137
"""
138138

139139
# construct the object -----
140+
_estimator_type = "classifier"
140141

141142
def __init__(
142143
self,
@@ -182,7 +183,6 @@ def __init__(
182183
self.type_fit = "classification"
183184
self.cv_calibration = cv_calibration
184185
self.calibration_method = calibration_method
185-
self._estimator_type = "classifier" # Explicitly mark as classifier
186186

187187
def __sklearn_clone__(self):
188188
"""Create a clone of the estimator.
@@ -478,4 +478,8 @@ def score(self, X, y, scoring=None):
478478
return -skm2.brier_score_loss(y, self.predict_proba(X))
479479

480480
if scoring == "neg_log_loss":
481-
return -skm2.log_loss(y, self.predict_proba(X))
481+
return -skm2.log_loss(y, self.predict_proba(X))
482+
483+
@property
484+
def _estimator_type(self):
485+
return "classifier"

nnetsauce/deep/deepClassifier.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class DeepClassifier(CustomClassifier, ClassifierMixin):
6565
print(clf.score(clf.predict(X_test), y_test))
6666
```
6767
"""
68+
_estimator_type = "classifier"
6869

6970
def __init__(
7071
self,
@@ -129,7 +130,6 @@ def __init__(
129130
self.cv_calibration = cv_calibration
130131
self.calibration_method = calibration_method
131132
self.obj = obj
132-
self._estimator_type = "classifier" # Add this line to explicitly mark as classifier
133133

134134
assert n_layers >= 1, "must have n_layers >= 1"
135135
self.stacked_obj = obj
@@ -636,3 +636,7 @@ def lazy_cross_val_optim(
636636
pass
637637

638638
return results
639+
640+
@property
641+
def _estimator_type(self):
642+
return "classifier"

nnetsauce/glm/glmClassifier.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ class GLMClassifier(GLM, ClassifierMixin):
8989
"""
9090

9191
# construct the object -----
92+
_estimator_type = "classifier"
9293

9394
def __init__(
9495
self,
@@ -377,3 +378,7 @@ def score(self, X, y, scoring=None):
377378

378379
if scoring == "neg_log_loss":
379380
return -skm2.log_loss(y, self.predict_proba(X))
381+
382+
@property
383+
def _estimator_type(self):
384+
return "classifier"

nnetsauce/multitask/multitaskClassifier.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ class MultitaskClassifier(Base, ClassifierMixin):
124124
"""
125125

126126
# construct the object -----
127+
_estimator_type = "classifier"
127128

128129
def __init__(
129130
self,
@@ -306,3 +307,8 @@ def decision_function(self, X, **kwargs):
306307
)[0]
307308

308309
return self.obj.decision_function(self.cook_test_set(X, **kwargs), **kwargs)
310+
311+
@property
312+
def _estimator_type(self):
313+
return "classifier"
314+

nnetsauce/multitask/simplemultitaskClassifier.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class SimpleMultitaskClassifier(Base, ClassifierMixin):
7272
"""
7373

7474
# construct the object -----
75+
_estimator_type = "classifier"
7576

7677
def __init__(
7778
self,
@@ -232,3 +233,7 @@ def decision_function(self, X, **kwargs):
232233
)[0]
233234

234235
return self.obj.decision_function(self.cook_test_set(X, **kwargs), **kwargs)
236+
237+
@property
238+
def _estimator_type(self):
239+
return "classifier"

nnetsauce/neuralnet/neuralnetclassification.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class NeuralNetClassifier(BaseEstimator, ClassifierMixin):
5555
set_weights(weights)
5656
Set the weights of the model.
5757
"""
58+
_estimator_type = "classifier"
5859

5960
def __init__(
6061
self,
@@ -137,4 +138,8 @@ def predict(self, X):
137138
Training vectors, where n_samples is the number of samples and
138139
n_features is the number of features.
139140
"""
140-
return self.regr.predict(X)
141+
return self.regr.predict(X)
142+
143+
@property
144+
def _estimator_type(self):
145+
return "classifier"

nnetsauce/randombag/randomBagClassifier.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class RandomBagClassifier(RandomBag, ClassifierMixin):
129129
"""
130130

131131
# construct the object -----
132+
_estimator_type = "classifier"
132133

133134
def __init__(
134135
self,
@@ -373,3 +374,9 @@ def predict_estimator(m):
373374
ensemble_proba += weights[i] * preds[i]
374375

375376
return ensemble_proba
377+
378+
379+
@property
380+
def _estimator_type(self):
381+
return "classifier"
382+

0 commit comments

Comments
 (0)