Skip to content

Commit

Permalink
fixed issue with python 3.11
Browse files Browse the repository at this point in the history
  • Loading branch information
ches-001 committed Jun 22, 2024
1 parent 278c315 commit 0fc5c31
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 325 deletions.
9 changes: 4 additions & 5 deletions tune_classifier/discriminant_analysis_classifier.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from ..baseline import BaseTuner
from optuna.trial import Trial
from dataclasses import dataclass
from types import MappingProxyType
from dataclasses import dataclass, field
from typing import Iterable, Optional, Dict, Any, Callable
from sklearn.discriminant_analysis import LinearDiscriminantAnalysis, QuadraticDiscriminantAnalysis

Expand All @@ -10,7 +9,7 @@
class LDAClassifierTuner(BaseTuner):
solver_space: Iterable[str] = ("svd", "lsqr", "eigen")
shrinkage_space: Iterable[str] = (None, "auto")
tol_space: Dict[str, Any] = MappingProxyType({"low":1e-6, "high":1e-3, "step":None, "log":True})
tol_space: Dict[str, Any] = field(default_factory=lambda: {"low":1e-6, "high":1e-3, "step":None, "log":True})
priors_space: Iterable[Optional[Iterable[float]]] = (None, )
store_covariance: Iterable[bool] = (False, )
covariance_estimator_space: Iterable[Optional[object]] = (None, )
Expand Down Expand Up @@ -44,8 +43,8 @@ def sample_model(self, trial: Optional[Trial] = None) -> Any:

@dataclass
class QDAClassifierTuner(BaseTuner):
reg_param_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
tol_space: Dict[str, Any] = MappingProxyType({"low":1e-6, "high":1e-3, "step":None, "log":True})
reg_param_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
tol_space: Dict[str, Any] = field(default_factory=lambda: {"low":1e-6, "high":1e-3, "step":None, "log":True})
priors_space: Iterable[Optional[Iterable[float]]] = (None,)
store_covariance: Iterable[bool] = (False,)

Expand Down
87 changes: 43 additions & 44 deletions tune_classifier/ensemble_classifier.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from ..baseline import BaseTuner
from optuna.trial import Trial
from dataclasses import dataclass
from dataclasses import dataclass, field
from typing import Iterable, Optional, Dict, Any, Union, Callable
from types import MappingProxyType
from sklearn.ensemble import (
RandomForestClassifier,
ExtraTreesClassifier,
Expand All @@ -14,25 +13,25 @@

@dataclass
class RandomForestClassifierTuner(BaseTuner):
n_estimators_space: Dict[str, Any] = MappingProxyType({"low":1, "high":200, "step":1, "log":True})
n_estimators_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":200, "step":1, "log":True})
criterion_space: Iterable[str] = ("gini", "entropy", "log_loss")
set_max_depth_space: Iterable[bool] = (True, False)
max_depth_space: Dict[str, Any] = MappingProxyType({"low":10, "high":2000, "step":1, "log":True})
min_samples_split_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
min_samples_leaf_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
min_weight_fraction_leaf_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":0.5, "step":None, "log":False})
max_depth_space: Dict[str, Any] = field(default_factory=lambda: {"low":10, "high":2000, "step":1, "log":True})
min_samples_split_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
min_samples_leaf_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
min_weight_fraction_leaf_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":0.5, "step":None, "log":False})
max_features_space: Iterable[str] = ("sqrt", "log2", None)
set_max_leaf_nodes_space: Iterable[bool] = (True, False)
max_leaf_nodes_space: Dict[str, Any] = MappingProxyType({"low":2, "high":10000, "step":1, "log":True})
min_impurity_decrease_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":1.0, "step":None, "log":False})
max_leaf_nodes_space: Dict[str, Any] = field(default_factory=lambda: {"low":2, "high":10000, "step":1, "log":True})
min_impurity_decrease_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":1.0, "step":None, "log":False})
bootstrap_space: Iterable[bool] = (True, False)
oob_score_space: Iterable[bool] = (True, False)
class_weight_space: Iterable[str] = ("balanced", "balanced_subsample")
set_random_state_space: Iterable[bool] = (False, )
random_state_space: Dict[str, Any] = MappingProxyType({"low":1, "high":10000, "step":1, "log":True})
ccp_alpha_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":1.0, "step":None, "log":False})
random_state_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":10000, "step":1, "log":True})
ccp_alpha_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":1.0, "step":None, "log":False})
set_max_samples_space: Iterable[bool] = (True, False)
max_samples_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
max_samples_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})

def sample_params(self, trial: Optional[Trial]=None) -> Dict[str, Any]:
super().sample_params(trial)
Expand Down Expand Up @@ -117,10 +116,10 @@ def sample_model(self, trial: Optional[Trial]=None) -> Any:
@dataclass
class AdaBoostClassifierTuner(BaseTuner):
estimator_space: Iterable[Optional[object]] = (None, )
n_estimators_space: Dict[str, Any] = MappingProxyType({"low":1, "high":200, "step":1, "log":True})
learning_rate_space: Dict[str, Any] = MappingProxyType({"low":0.01, "high":1, "step":None, "log":True})
n_estimators_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":200, "step":1, "log":True})
learning_rate_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.01, "high":1, "step":None, "log":True})
algorithm_space: Iterable[str] = ("SAMME", "SAMME.R")
random_state_space: Dict[str, Any] = MappingProxyType({"low":1, "high":10000, "step":1, "log":True})
random_state_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":10000, "step":1, "log":True})

def sample_params(self, trial: Optional[Trial]=None) -> Dict[str, Any]:
super().sample_params(trial)
Expand All @@ -146,26 +145,26 @@ def sample_model(self, trial: Optional[Trial]=None) -> Any:
@dataclass
class GradientBoostingClassifierTuner(BaseTuner):
loss_space: Iterable[str] = ("log_loss", )
learning_rate_space: Dict[str, Any] = MappingProxyType({"low":0.001, "high":1.0, "step":None, "log":True})
n_estimators_space: Dict[str, Any] = MappingProxyType({"low":1, "high":100, "step":1, "log":True})
subsample_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
learning_rate_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.001, "high":1.0, "step":None, "log":True})
n_estimators_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":100, "step":1, "log":True})
subsample_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
criterion_space: Iterable[str] = ("friedman_mse", "squared_error")
min_samples_split_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
min_samples_leaf_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
min_weight_fraction_leaf_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":0.5, "step":None, "log":False})
min_samples_split_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
min_samples_leaf_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
min_weight_fraction_leaf_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":0.5, "step":None, "log":False})
set_max_depth_space: Iterable[bool] = (True, False)
max_depth_space: Dict[str, Any] = MappingProxyType({"low":10, "high":2000, "step":1, "log":True})
min_impurity_decrease_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":1.0, "step":None, "log":False})
max_depth_space: Dict[str, Any] = field(default_factory=lambda: {"low":10, "high":2000, "step":1, "log":True})
min_impurity_decrease_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":1.0, "step":None, "log":False})
init_space: Iterable[Optional[object]] = (None, )
max_features_space: Iterable[str] = ("sqrt", "log2")
set_max_leaf_nodes_space: Iterable[bool] = (True, False)
max_leaf_nodes_space: Iterable[Optional[int]] = MappingProxyType({"low":2, "high":10000, "step":1, "log":True})
validation_fraction_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":0.5, "step":None, "log":False})
max_leaf_nodes_space: Iterable[Optional[int]] = field(default_factory=lambda: {"low":2, "high":10000, "step":1, "log":True})
validation_fraction_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":0.5, "step":None, "log":False})
set_n_iter_no_change_space:Iterable[bool] = (True, False)
n_iter_no_change_space: Dict[str, Any] = MappingProxyType({"low":1, "high":100, "step":1, "log":True})
random_state_space: Dict[str, Any] = MappingProxyType({"low":1, "high":10000, "step":1, "log":True})
tol_space: Dict[str, Any] = MappingProxyType({"low":1e-6, "high":1e-3, "step":None, "log":True})
ccp_alpha_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":1.0, "step":None, "log":False})
n_iter_no_change_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":100, "step":1, "log":True})
random_state_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":10000, "step":1, "log":True})
tol_space: Dict[str, Any] = field(default_factory=lambda: {"low":1e-6, "high":1e-3, "step":None, "log":True})
ccp_alpha_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":1.0, "step":None, "log":False})

def sample_params(self, trial: Optional[Trial]=None) -> Dict[str, Any]:
super().sample_params(trial)
Expand Down Expand Up @@ -231,13 +230,13 @@ def sample_model(self, trial: Optional[Trial]=None) -> Any:
@dataclass
class BaggingClassifierTuner(BaseTuner):
estimator_space: Iterable[Optional[object]] = (None, )
n_estimators_space: Dict[str, Any] = MappingProxyType({"low":1, "high":100, "step":1, "log":True})
max_samples_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
max_features_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":1.0, "step":None, "log":False})
n_estimators_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":100, "step":1, "log":True})
max_samples_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
max_features_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":1.0, "step":None, "log":False})
bootstrap_space: Iterable[bool] = (True, False)
bootstrap_features_space: Iterable[bool] = (True, False)
oob_score_space: Iterable[bool] = (True, False)
random_state_space: Dict[str, Any] = MappingProxyType({"low":1, "high":10000, "step":1, "log":True})
random_state_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":10000, "step":1, "log":True})

def sample_params(self, trial: Optional[Trial]=None) -> Dict[str, Any]:
super().sample_params(trial)
Expand Down Expand Up @@ -275,24 +274,24 @@ def sample_model(self, trial: Optional[Trial]=None) -> Any:
@dataclass
class HistGradientBoostingClassifierTuner(BaseTuner):
loss_space: Iterable[str] = ("log_loss", )
learning_rate_space: Dict[str, Any] = MappingProxyType({"low":0.001, "high":1.0, "step":None, "log":True})
max_iter_space: Dict[str, Any] = MappingProxyType({"low":10, "high":1000, "step":1, "log":True})
learning_rate_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.001, "high":1.0, "step":None, "log":True})
max_iter_space: Dict[str, Any] = field(default_factory=lambda: {"low":10, "high":1000, "step":1, "log":True})
set_max_leaf_nodes_space: Iterable[bool] = (True, False)
max_leaf_nodes_space: Iterable[Optional[int]] = MappingProxyType({"low":2, "high":10000, "step":1, "log":True})
max_leaf_nodes_space: Iterable[Optional[int]] = field(default_factory=lambda: {"low":2, "high":10000, "step":1, "log":True})
set_max_depth_space: Iterable[bool] = (True, False)
max_depth_space: Dict[str, Any] = MappingProxyType({"low":10, "high":2000, "step":1, "log":True})
min_samples_leaf_space: Dict[str, Any] = MappingProxyType({"low":1, "high":200, "step":1, "log":True})
l2_regularization_space: Dict[str, Any] = MappingProxyType({"low":0.0, "high":1.0, "step":None, "log":False})
max_bins_space: Dict[str, Any] = MappingProxyType({"low":10, "high":255, "step":1, "log":True})
max_depth_space: Dict[str, Any] = field(default_factory=lambda: {"low":10, "high":2000, "step":1, "log":True})
min_samples_leaf_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":200, "step":1, "log":True})
l2_regularization_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.0, "high":1.0, "step":None, "log":False})
max_bins_space: Dict[str, Any] = field(default_factory=lambda: {"low":10, "high":255, "step":1, "log":True})
categorical_features_space: Iterable[Any] = (None, )
monotonic_cst_space: Iterable[Any] = (None, )
interaction_cst_space: Iterable[Any] = (None, )
early_stopping_space: Iterable[bool] = ("auto", True, False)
scoring_space: Iterable[Optional[Union[str, Callable]]] = ("loss", None)
validation_fraction_space: Dict[str, Any] = MappingProxyType({"low":0.1, "high":0.5, "step":None, "log":True})
n_iter_no_change_space: Dict[str, Any] = MappingProxyType({"low":1, "high":100, "step":1, "log":True})
tol_space: Dict[str, Any] = MappingProxyType({"low":1e-6, "high":1e-3, "step":None, "log":True})
random_state_space: Dict[str, Any] = MappingProxyType({"low":1, "high":10000, "step":1, "log":True})
validation_fraction_space: Dict[str, Any] = field(default_factory=lambda: {"low":0.1, "high":0.5, "step":None, "log":True})
n_iter_no_change_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":100, "step":1, "log":True})
tol_space: Dict[str, Any] = field(default_factory=lambda: {"low":1e-6, "high":1e-3, "step":None, "log":True})
random_state_space: Dict[str, Any] = field(default_factory=lambda: {"low":1, "high":10000, "step":1, "log":True})
class_weight_space: Iterable[str] = ("balanced", )

def sample_params(self, trial: Optional[Trial]=None) -> Dict[str, Any]:
Expand Down
Loading

0 comments on commit 0fc5c31

Please sign in to comment.