PyIAML 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- iaml/__init__.py +56 -0
- iaml/actionable.py +11 -0
- iaml/actionables/__init__.py +21 -0
- iaml/actionables/boosting/__init__.py +4 -0
- iaml/actionables/boosting/act_adaboost.py +59 -0
- iaml/actionables/cleaning/__init__.py +26 -0
- iaml/actionables/cleaning/act_categorical_imputer.py +124 -0
- iaml/actionables/cleaning/act_count_vectorizer.py +204 -0
- iaml/actionables/cleaning/act_drop_categorical_column.py +51 -0
- iaml/actionables/cleaning/act_drop_date_column.py +48 -0
- iaml/actionables/cleaning/act_drop_high_cardinality_categorical.py +337 -0
- iaml/actionables/cleaning/act_drop_numerical_column.py +75 -0
- iaml/actionables/cleaning/act_drop_textual_column.py +51 -0
- iaml/actionables/cleaning/act_encode_target_column.py +56 -0
- iaml/actionables/cleaning/act_frequency_encoder.py +127 -0
- iaml/actionables/cleaning/act_hashing_vectorizer.py +186 -0
- iaml/actionables/cleaning/act_knn_imputer.py +152 -0
- iaml/actionables/cleaning/act_mean_column.py +79 -0
- iaml/actionables/cleaning/act_mice.py +464 -0
- iaml/actionables/cleaning/act_missing_count_feature.py +109 -0
- iaml/actionables/cleaning/act_missing_indicator.py +124 -0
- iaml/actionables/cleaning/act_onehot.py +65 -0
- iaml/actionables/cleaning/act_ordinal_encoder.py +177 -0
- iaml/actionables/cleaning/act_rare_category_grouper.py +173 -0
- iaml/actionables/cleaning/act_simple_imputer.py +109 -0
- iaml/actionables/cleaning/act_split_date.py +68 -0
- iaml/actionables/cleaning/act_target_encoder.py +274 -0
- iaml/actionables/cleaning/act_text_normalizer.py +241 -0
- iaml/actionables/cleaning/act_tf_idf.py +80 -0
- iaml/actionables/cleaning/act_word2vec.py +150 -0
- iaml/actionables/features_precleaning/__init__.py +12 -0
- iaml/actionables/features_precleaning/act_coerce_numeric_strings.py +194 -0
- iaml/actionables/features_precleaning/act_date_converter.py +99 -0
- iaml/actionables/features_precleaning/act_drop_bad_quality_rows.py +77 -0
- iaml/actionables/features_precleaning/act_drop_duplicate_rows.py +131 -0
- iaml/actionables/features_precleaning/act_drop_high_missing_columns.py +94 -0
- iaml/actionables/features_precleaning/act_drop_id_like_columns.py +294 -0
- iaml/actionables/features_precleaning/act_normalize_column_names.py +157 -0
- iaml/actionables/features_precleaning/act_sentinel_to_na_n.py +270 -0
- iaml/actionables/features_precleaning/act_trim_space.py +79 -0
- iaml/actionables/features_preprocessing/__init__.py +18 -0
- iaml/actionables/features_preprocessing/act_cyclical_date_encoding.py +212 -0
- iaml/actionables/features_preprocessing/act_fast_ica.py +161 -0
- iaml/actionables/features_preprocessing/act_feature_agglomeration.py +90 -0
- iaml/actionables/features_preprocessing/act_k_bins_discretizer.py +207 -0
- iaml/actionables/features_preprocessing/act_k_means_features.py +296 -0
- iaml/actionables/features_preprocessing/act_kernel_pca.py +143 -0
- iaml/actionables/features_preprocessing/act_log_transformer.py +122 -0
- iaml/actionables/features_preprocessing/act_nystroem.py +100 -0
- iaml/actionables/features_preprocessing/act_pca.py +77 -0
- iaml/actionables/features_preprocessing/act_polynomial_features.py +86 -0
- iaml/actionables/features_preprocessing/act_power_transformer.py +106 -0
- iaml/actionables/features_preprocessing/act_quantile_transformer.py +114 -0
- iaml/actionables/features_preprocessing/act_rbf_sampler.py +88 -0
- iaml/actionables/features_preprocessing/act_select_percentile.py +112 -0
- iaml/actionables/features_preprocessing/act_sparse_random_projection.py +157 -0
- iaml/actionables/features_preprocessing/act_truncated_svd.py +137 -0
- iaml/actionables/features_selection/__init__.py +8 -0
- iaml/actionables/features_selection/act_permutation_importance_selector.py +421 -0
- iaml/actionables/features_selection/act_remove_high_correlated_column.py +70 -0
- iaml/actionables/features_selection/act_remove_low_variance_column.py +74 -0
- iaml/actionables/features_selection/act_rfe.py +214 -0
- iaml/actionables/features_selection/act_select_from_model.py +325 -0
- iaml/actionables/features_selection/act_select_k_best.py +181 -0
- iaml/actionables/features_selection/act_vif_selector.py +130 -0
- iaml/actionables/imbalance/__init__.py +10 -0
- iaml/actionables/imbalance/act_adasyn.py +150 -0
- iaml/actionables/imbalance/act_borderline_smote.py +171 -0
- iaml/actionables/imbalance/act_near_miss.py +158 -0
- iaml/actionables/imbalance/act_random_over_sampling.py +60 -0
- iaml/actionables/imbalance/act_random_under_sampler.py +135 -0
- iaml/actionables/imbalance/act_smote.py +162 -0
- iaml/actionables/imbalance/act_smote_tomek.py +182 -0
- iaml/actionables/imbalance/act_smoteenn.py +193 -0
- iaml/actionables/imbalance/act_tomek_links.py +138 -0
- iaml/actionables/normalize/__init__.py +6 -0
- iaml/actionables/normalize/act_max_abs_scaler.py +78 -0
- iaml/actionables/normalize/act_minmax_scaler.py +56 -0
- iaml/actionables/normalize/act_normalizer.py +95 -0
- iaml/actionables/normalize/act_robust_scaler.py +111 -0
- iaml/actionables/normalize/act_standard_scaler.py +55 -0
- iaml/actionables/predictors/__init__.py +6 -0
- iaml/actionables/predictors/_xgboost.py +16 -0
- iaml/actionables/predictors/classifier/__init__.py +26 -0
- iaml/actionables/predictors/classifier/act_bagging_classifier.py +113 -0
- iaml/actionables/predictors/classifier/act_bernoulli_nb.py +89 -0
- iaml/actionables/predictors/classifier/act_catboost_classifier.py +135 -0
- iaml/actionables/predictors/classifier/act_complement_nb.py +106 -0
- iaml/actionables/predictors/classifier/act_decision_tree_classifier.py +117 -0
- iaml/actionables/predictors/classifier/act_extra_trees_classifier.py +115 -0
- iaml/actionables/predictors/classifier/act_gaussian_nb.py +53 -0
- iaml/actionables/predictors/classifier/act_hist_gradient_boosting_classifier.py +144 -0
- iaml/actionables/predictors/classifier/act_knn.py +86 -0
- iaml/actionables/predictors/classifier/act_light_gbm_classifier.py +211 -0
- iaml/actionables/predictors/classifier/act_linear_discriminant_analysis.py +63 -0
- iaml/actionables/predictors/classifier/act_linear_svc.py +134 -0
- iaml/actionables/predictors/classifier/act_logistic_regression.py +92 -0
- iaml/actionables/predictors/classifier/act_mlp_classifier.py +107 -0
- iaml/actionables/predictors/classifier/act_multinomial_nb.py +76 -0
- iaml/actionables/predictors/classifier/act_passive_aggressive_classifier.py +141 -0
- iaml/actionables/predictors/classifier/act_quadratic_discriminant_analysis.py +72 -0
- iaml/actionables/predictors/classifier/act_randomforest.py +113 -0
- iaml/actionables/predictors/classifier/act_ridge_classifier.py +116 -0
- iaml/actionables/predictors/classifier/act_sgd_classifier.py +149 -0
- iaml/actionables/predictors/classifier/act_svm_svc.py +88 -0
- iaml/actionables/predictors/classifier/act_xgboost.py +111 -0
- iaml/actionables/predictors/regressor/__init__.py +27 -0
- iaml/actionables/predictors/regressor/act_ada_boost_regressor.py +75 -0
- iaml/actionables/predictors/regressor/act_ard_regression.py +95 -0
- iaml/actionables/predictors/regressor/act_catboost_regressor.py +134 -0
- iaml/actionables/predictors/regressor/act_decision_tree_regressor.py +111 -0
- iaml/actionables/predictors/regressor/act_elastic_net_regressor.py +109 -0
- iaml/actionables/predictors/regressor/act_extra_trees_regressor.py +113 -0
- iaml/actionables/predictors/regressor/act_gaussian_process_regressor.py +55 -0
- iaml/actionables/predictors/regressor/act_gboost_regressor.py +95 -0
- iaml/actionables/predictors/regressor/act_hist_gradient_boosting_regressor.py +105 -0
- iaml/actionables/predictors/regressor/act_huber_regressor.py +101 -0
- iaml/actionables/predictors/regressor/act_knn_regressor.py +86 -0
- iaml/actionables/predictors/regressor/act_lasso_regressor.py +103 -0
- iaml/actionables/predictors/regressor/act_light_gbm_regressor.py +201 -0
- iaml/actionables/predictors/regressor/act_linear_regression.py +43 -0
- iaml/actionables/predictors/regressor/act_mlp_regressor.py +104 -0
- iaml/actionables/predictors/regressor/act_poisson_regressor.py +111 -0
- iaml/actionables/predictors/regressor/act_quantile_regressor.py +87 -0
- iaml/actionables/predictors/regressor/act_randomforest_regressor.py +116 -0
- iaml/actionables/predictors/regressor/act_ransac_regressor.py +106 -0
- iaml/actionables/predictors/regressor/act_ridge_regressor.py +107 -0
- iaml/actionables/predictors/regressor/act_sgd_regressor.py +106 -0
- iaml/actionables/predictors/regressor/act_svm_svr.py +81 -0
- iaml/actionables/predictors/regressor/act_xgboost_regressor.py +97 -0
- iaml/actionables/predictors/survival/__init__.py +12 -0
- iaml/actionables/predictors/survival/act_aalen_additive_model.py +83 -0
- iaml/actionables/predictors/survival/act_cox.py +110 -0
- iaml/actionables/predictors/survival/act_coxnet_survival_analysis.py +134 -0
- iaml/actionables/predictors/survival/act_extra_survival_trees.py +101 -0
- iaml/actionables/predictors/survival/act_fast_survival_svm.py +102 -0
- iaml/actionables/predictors/survival/act_gradient_boosting_survival_analysis.py +93 -0
- iaml/actionables/predictors/survival/act_random_survival_forest.py +91 -0
- iaml/actionables/predictors/survival/act_survival_component_wise_gboost.py +80 -0
- iaml/actionables/predictors/survival/act_survival_tree.py +120 -0
- iaml/actionables/predictors/survival/act_survival_xgboost.py +9 -0
- iaml/actionables/predictors/survival/act_weibull_aft.py +230 -0
- iaml/cache.py +61 -0
- iaml/cache_keys.py +57 -0
- iaml/candidate.py +736 -0
- iaml/core_dispatcher.py +125 -0
- iaml/data_type.py +11 -0
- iaml/dataset.py +506 -0
- iaml/decorators/__init__.py +3 -0
- iaml/decorators/all.py +4 -0
- iaml/decorators/is_step.py +45 -0
- iaml/decorators/runner.py +100 -0
- iaml/explanation.py +112 -0
- iaml/iaml.py +1072 -0
- iaml/iaml_pipeline.py +600 -0
- iaml/logger.py +138 -0
- iaml/meta_explorer_step.py +62 -0
- iaml/meta_ordered_step.py +28 -0
- iaml/meta_partial_explorer_step.py +34 -0
- iaml/meta_singleton.py +24 -0
- iaml/metastep.py +211 -0
- iaml/metric.py +111 -0
- iaml/metric_plot.py +82 -0
- iaml/metrics/__init__.py +21 -0
- iaml/metrics/_classification.py +28 -0
- iaml/metrics/_survival_times.py +22 -0
- iaml/metrics/accuracy_metric.py +59 -0
- iaml/metrics/balanced_accuracy_metric.py +67 -0
- iaml/metrics/brier_score.py +90 -0
- iaml/metrics/classification_error_metric.py +66 -0
- iaml/metrics/concordance_index_ipcw.py +84 -0
- iaml/metrics/concordance_index_metric.py +67 -0
- iaml/metrics/cumulative_dynamic_auc.py +119 -0
- iaml/metrics/f1_score_metric.py +71 -0
- iaml/metrics/integrated_brier_score.py +98 -0
- iaml/metrics/integrated_brier_score_loss.py +41 -0
- iaml/metrics/mean_absolute_error_metric.py +46 -0
- iaml/metrics/mean_squared_error_metric.py +46 -0
- iaml/metrics/mean_squared_log_error_metric.py +49 -0
- iaml/metrics/median_absolute_error_metric.py +48 -0
- iaml/metrics/precision_metric.py +63 -0
- iaml/metrics/r2_score_metric.py +45 -0
- iaml/metrics/recall_metric.py +65 -0
- iaml/metrics/roc_auc_metric.py +50 -0
- iaml/metrics/specificity_metric.py +44 -0
- iaml/metrics/specificity_multiclass_metric.py +55 -0
- iaml/metrics/specificity_multilabel_metric.py +60 -0
- iaml/optimizers/__init__.py +5 -0
- iaml/optimizers/bayesian_optimizer.py +193 -0
- iaml/optimizers/genetic_optimizer.py +284 -0
- iaml/optimizers/optimizer.py +31 -0
- iaml/optimizers/random_optimizer.py +101 -0
- iaml/plot.py +138 -0
- iaml/plots/__init__.py +32 -0
- iaml/plots/bar_plot.py +141 -0
- iaml/plots/box_plot.py +166 -0
- iaml/plots/class_prediction_error_plot.py +37 -0
- iaml/plots/classification_report_plot.py +35 -0
- iaml/plots/confusion_matrix_plot.py +34 -0
- iaml/plots/correlation_heatmap_plot.py +201 -0
- iaml/plots/cumulative_hazard_plot.py +72 -0
- iaml/plots/density_plot.py +210 -0
- iaml/plots/histogram_plot.py +179 -0
- iaml/plots/kaplan_meier_comparison_plot.py +89 -0
- iaml/plots/line_plot.py +70 -0
- iaml/plots/missingness_heatmap_plot.py +203 -0
- iaml/plots/outlier_plot.py +217 -0
- iaml/plots/pair_plot.py +228 -0
- iaml/plots/precision_recall_curve_plot.py +86 -0
- iaml/plots/prediction_error_plot.py +34 -0
- iaml/plots/qq_plot.py +220 -0
- iaml/plots/residual_plot.py +38 -0
- iaml/plots/roc_dynamique_curve_plot.py +79 -0
- iaml/plots/rocauc_plot.py +96 -0
- iaml/plots/shap_plot.py +187 -0
- iaml/plots/target_distribution_plot.py +241 -0
- iaml/plots/violin_plot.py +206 -0
- iaml/predictor.py +139 -0
- iaml/reference.py +65 -0
- iaml/shared_cache.py +90 -0
- iaml/sklearn_preprocessor.py +74 -0
- iaml/splitters/__init__.py +3 -0
- iaml/splitters/kfold_splitter.py +32 -0
- iaml/splitters/random_splitter.py +26 -0
- iaml/stack.py +39 -0
- iaml/statistic.py +66 -0
- iaml/statistics/__init__.py +77 -0
- iaml/statistics/anova_statistic.py +80 -0
- iaml/statistics/cardinality_ratio_statistic.py +63 -0
- iaml/statistics/category_cooccurrence_statistic.py +79 -0
- iaml/statistics/chi_square_statistic.py +81 -0
- iaml/statistics/coef_variation_statistic.py +72 -0
- iaml/statistics/correlation_with_target.py +105 -0
- iaml/statistics/count.py +72 -0
- iaml/statistics/data_type_summary_statistic.py +74 -0
- iaml/statistics/duplicate_row_statistic.py +56 -0
- iaml/statistics/effect_size_statistic.py +129 -0
- iaml/statistics/entropy_statistic.py +69 -0
- iaml/statistics/event_rate_statistic.py +52 -0
- iaml/statistics/grouped_mean_statistic.py +60 -0
- iaml/statistics/iqr_statistic.py +66 -0
- iaml/statistics/kurtosis.py +50 -0
- iaml/statistics/mad_statistic.py +66 -0
- iaml/statistics/mean.py +61 -0
- iaml/statistics/median_statistic.py +61 -0
- iaml/statistics/minmax.py +60 -0
- iaml/statistics/missing_rate_statistic.py +62 -0
- iaml/statistics/mode.py +47 -0
- iaml/statistics/most_frequent_ratio.py +81 -0
- iaml/statistics/outlier_count_iqr_statistic.py +76 -0
- iaml/statistics/quantile.py +59 -0
- iaml/statistics/range.py +53 -0
- iaml/statistics/rare_category_rate.py +92 -0
- iaml/statistics/skewness.py +53 -0
- iaml/statistics/stdev.py +50 -0
- iaml/statistics/summary_table_statistic.py +60 -0
- iaml/statistics/time_by_group_statistic.py +83 -0
- iaml/statistics/time_summary_statistic.py +56 -0
- iaml/statistics/top_k_value_counts.py +68 -0
- iaml/statistics/unique_count_statistic.py +57 -0
- iaml/statistics/value_counts.py +63 -0
- iaml/statistics/variance.py +51 -0
- iaml/statistics/violin.py +63 -0
- iaml/step.py +600 -0
- iaml/step_cache.py +87 -0
- iaml/step_wrapper.py +79 -0
- iaml/timed_pool_executor.py +492 -0
- iaml/type_of_target.py +68 -0
- iaml/void_step.py +101 -0
- iaml/worker_manager.py +169 -0
- iaml/wrapper/__init__.py +4 -0
- iaml/wrapper/wrap_basic_gridsearch.py +68 -0
- iaml/wrapper/wrap_genetic_gridsearch.py +293 -0
- iaml/wrapper/wrap_iterative_gridsearch.py +399 -0
- pyiaml-1.0.0.dist-info/METADATA +802 -0
- pyiaml-1.0.0.dist-info/RECORD +279 -0
- pyiaml-1.0.0.dist-info/WHEEL +5 -0
- pyiaml-1.0.0.dist-info/licenses/LICENSE +674 -0
- pyiaml-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
"""[STEP] Complement NB"""
|
|
2
|
+
|
|
3
|
+
import textwrap
|
|
4
|
+
from typing import Any
|
|
5
|
+
from sklearn.naive_bayes import ComplementNB
|
|
6
|
+
from ....predictor import Predictor
|
|
7
|
+
from ....dataset import Dataset
|
|
8
|
+
from ....candidate import Candidate
|
|
9
|
+
from ....data_type import DataType
|
|
10
|
+
from ....decorators.all import is_step
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
14
|
+
class ActComplementNB(Predictor):
|
|
15
|
+
"""[STEP] Complement NB"""
|
|
16
|
+
|
|
17
|
+
name: str = "Complement NB"
|
|
18
|
+
_usage: str = "Use when you need a fast NB baseline for imbalanced count features vs ActBernoulliNb. Applicable to non-negative numeric data (counts/TF-IDF) for binary or multiclass classification. Avoid when features are negative/continuous or nonlinear patterns favor ActCatBoost."
|
|
19
|
+
_description: str = textwrap.dedent('''\
|
|
20
|
+
ComplementNB is a Naive Bayes variant tailored for imbalanced text
|
|
21
|
+
classification by using statistics from the complement of each class.''')
|
|
22
|
+
_description_long: str = textwrap.dedent('''\
|
|
23
|
+
ComplementNB modifies the traditional multinomial Naive Bayes formula
|
|
24
|
+
by estimating feature weights from the complement of each class. This
|
|
25
|
+
reduces the bias toward frequent classes, making it effective for
|
|
26
|
+
imbalanced text datasets and high-dimensional sparse features.''')
|
|
27
|
+
refs: list[dict[str, Any]] = [
|
|
28
|
+
{
|
|
29
|
+
'year': 2003,
|
|
30
|
+
'name': 'Tackling the Poor Assumptions of Naive Bayes Text Classifiers',
|
|
31
|
+
'authors': [
|
|
32
|
+
'Jason D. M. Rennie',
|
|
33
|
+
'Lawrence Shih',
|
|
34
|
+
'Jaime Teevan',
|
|
35
|
+
'David R. Karger'
|
|
36
|
+
],
|
|
37
|
+
'doi': 'https://dl.acm.org/doi/10.5555/944919.944939',
|
|
38
|
+
'publisher': (
|
|
39
|
+
'Proceedings of the 20th International Conference on Machine Learning '
|
|
40
|
+
'(ICML), pages 616--623'
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
def __init__(self):
|
|
46
|
+
self.configuration = {
|
|
47
|
+
'alpha': {
|
|
48
|
+
'description': textwrap.dedent('''\
|
|
49
|
+
Additive (Laplace/Lidstone) smoothing parameter (set
|
|
50
|
+
alpha=0 for no smoothing).'''),
|
|
51
|
+
'default': 1.0,
|
|
52
|
+
'range': [0.01, 100.0]
|
|
53
|
+
},
|
|
54
|
+
'fit_prior': {
|
|
55
|
+
'description': textwrap.dedent('''\
|
|
56
|
+
Whether to learn class prior probabilities or not. If
|
|
57
|
+
false, a uniform prior will be used.'''),
|
|
58
|
+
'default': True,
|
|
59
|
+
'categorical': [True, False]
|
|
60
|
+
},
|
|
61
|
+
'norm': {
|
|
62
|
+
'description': textwrap.dedent('''\
|
|
63
|
+
Whether to normalize by the total feature counts per class
|
|
64
|
+
to reduce the influence of document length.'''),
|
|
65
|
+
'default': False,
|
|
66
|
+
'categorical': [True, False]
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
self.model: ComplementNB = None
|
|
70
|
+
self.columns: list[str] = []
|
|
71
|
+
|
|
72
|
+
def _select_features(self, X):
|
|
73
|
+
if self.columns and hasattr(X, 'columns'):
|
|
74
|
+
return X[self.columns]
|
|
75
|
+
return X
|
|
76
|
+
|
|
77
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
78
|
+
self.columns = dataset.get_columns_names_by_type(DataType.NUMERIC)
|
|
79
|
+
if not self.columns:
|
|
80
|
+
self.columns = dataset.features
|
|
81
|
+
|
|
82
|
+
self.model = ComplementNB(**self.passthrough_parameters())
|
|
83
|
+
self.model.fit(self._select_features(dataset.X), dataset.y)
|
|
84
|
+
return self
|
|
85
|
+
|
|
86
|
+
def predict(self, X):
|
|
87
|
+
return super().predict(self._select_features(X))
|
|
88
|
+
|
|
89
|
+
def score(self, X, y=None, *args, **kwargs):
|
|
90
|
+
return self.model.score(self._select_features(X), y, *args, **kwargs)
|
|
91
|
+
|
|
92
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
93
|
+
if dataset.type_of_target not in ['binary', 'multiclass']:
|
|
94
|
+
return False
|
|
95
|
+
|
|
96
|
+
columns = dataset.get_columns_names_by_type(DataType.NUMERIC)
|
|
97
|
+
if not columns:
|
|
98
|
+
return False
|
|
99
|
+
|
|
100
|
+
try:
|
|
101
|
+
return not (dataset.X[columns] < 0).any().any()
|
|
102
|
+
except (TypeError, ValueError):
|
|
103
|
+
return False
|
|
104
|
+
|
|
105
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
106
|
+
return 0.5 # neutral
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""[STEP] Decision Tree Classifier"""
|
|
2
|
+
import textwrap
|
|
3
|
+
from typing import Any
|
|
4
|
+
from sklearn.tree import DecisionTreeClassifier
|
|
5
|
+
from ....predictor import Predictor
|
|
6
|
+
from ....dataset import Dataset
|
|
7
|
+
from ....candidate import Candidate
|
|
8
|
+
from ....data_type import DataType
|
|
9
|
+
from ....decorators.all import is_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
13
|
+
class ActDecisionTreeClassifier(Predictor):
|
|
14
|
+
"""[STEP] Decision Tree Classifier"""
|
|
15
|
+
|
|
16
|
+
name: str = "Decision Tree Classifier"
|
|
17
|
+
_description: str = textwrap.dedent('''\
|
|
18
|
+
DecisionTreeClassifier is a tree-based algorithm that learns
|
|
19
|
+
if-then rules to predict a categorical target.''')
|
|
20
|
+
_description_long: str = textwrap.dedent('''\
|
|
21
|
+
DecisionTreeClassifier builds a tree by recursively splitting the data
|
|
22
|
+
on feature thresholds to reduce impurity. The resulting tree can be
|
|
23
|
+
inspected for interpretability.''')
|
|
24
|
+
_usage: str = "Use when you want a fast, interpretable baseline; compare ActExtraTreesClassifier or ActBaggingClassifier. Applicable to tabular classification with numeric features and binary or multiclass targets. Avoid when you need top accuracy or stability on noisy data."
|
|
25
|
+
refs: list[dict[str, Any]] = [
|
|
26
|
+
{
|
|
27
|
+
'year': 1984,
|
|
28
|
+
'name': 'Classification and Regression Trees',
|
|
29
|
+
'authors': [
|
|
30
|
+
'Leo Breiman',
|
|
31
|
+
'Jerome Friedman',
|
|
32
|
+
'Richard Olshen',
|
|
33
|
+
'Charles Stone'
|
|
34
|
+
],
|
|
35
|
+
'publisher': 'Wadsworth'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __init__(self):
|
|
40
|
+
self.configuration = {
|
|
41
|
+
'max_depth': {
|
|
42
|
+
'description': 'Maximum depth of the tree.',
|
|
43
|
+
'default': 5,
|
|
44
|
+
'range': [1, 50]
|
|
45
|
+
},
|
|
46
|
+
'min_samples_leaf': {
|
|
47
|
+
'description': 'Minimum number of samples required to be at a leaf node.',
|
|
48
|
+
'default': 1,
|
|
49
|
+
'range': [1, 20]
|
|
50
|
+
},
|
|
51
|
+
'min_samples_split': {
|
|
52
|
+
'description': 'Minimum number of samples required to split an internal node.',
|
|
53
|
+
'default': 2,
|
|
54
|
+
'range': [2, 50]
|
|
55
|
+
},
|
|
56
|
+
'max_features': {
|
|
57
|
+
'description': textwrap.dedent('''\
|
|
58
|
+
The number of features to consider when looking for the best split.
|
|
59
|
+
Use a float to specify a fraction of features.'''),
|
|
60
|
+
'default': 1.0,
|
|
61
|
+
'range': [0.1, 1.0]
|
|
62
|
+
},
|
|
63
|
+
'criterion': {
|
|
64
|
+
'description': 'Function to measure the quality of a split.',
|
|
65
|
+
'default': 'gini',
|
|
66
|
+
'categorical': ['gini', 'entropy', 'log_loss']
|
|
67
|
+
},
|
|
68
|
+
'splitter': {
|
|
69
|
+
'description': 'Strategy used to choose the split at each node.',
|
|
70
|
+
'default': 'best',
|
|
71
|
+
'categorical': ['best', 'random']
|
|
72
|
+
},
|
|
73
|
+
'class_weight': {
|
|
74
|
+
'description': textwrap.dedent('''\
|
|
75
|
+
The "balanced" mode uses values of y to adjust weights inversely
|
|
76
|
+
proportional to class frequencies.'''),
|
|
77
|
+
'default': None,
|
|
78
|
+
'categorical': [None, 'balanced']
|
|
79
|
+
},
|
|
80
|
+
'random_state': {
|
|
81
|
+
'description': 'Random state for reproducibility.',
|
|
82
|
+
'default': 42
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
self.model: DecisionTreeClassifier = None
|
|
86
|
+
self.columns: list[str] = []
|
|
87
|
+
|
|
88
|
+
def _select_features(self, X):
|
|
89
|
+
if self.columns and hasattr(X, 'columns'):
|
|
90
|
+
return X[self.columns]
|
|
91
|
+
return X
|
|
92
|
+
|
|
93
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
94
|
+
self.columns = dataset.get_columns_names_by_type(DataType.NUMERIC)
|
|
95
|
+
if not self.columns:
|
|
96
|
+
self.columns = dataset.features
|
|
97
|
+
|
|
98
|
+
self.model = DecisionTreeClassifier(**self.passthrough_parameters())
|
|
99
|
+
self.model.fit(self._select_features(dataset.X), dataset.y)
|
|
100
|
+
return self
|
|
101
|
+
|
|
102
|
+
def predict(self, X):
|
|
103
|
+
return super().predict(self._select_features(X))
|
|
104
|
+
|
|
105
|
+
def predict_proba(self, X):
|
|
106
|
+
return super().predict_proba(self._select_features(X))
|
|
107
|
+
|
|
108
|
+
def score(self, X, y=None, *args, **kwargs):
|
|
109
|
+
return self.model.score(self._select_features(X), y, *args, **kwargs)
|
|
110
|
+
|
|
111
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
112
|
+
return dataset.type_of_target in \
|
|
113
|
+
['binary', 'multiclass', 'multilabel-indicator'] \
|
|
114
|
+
and bool(dataset.get_columns_names_by_type(DataType.NUMERIC))
|
|
115
|
+
|
|
116
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
117
|
+
return 0.5 # neutral
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"""[STEP] Extra Trees Classifier"""
|
|
2
|
+
import textwrap
|
|
3
|
+
from typing import Any
|
|
4
|
+
from sklearn.ensemble import ExtraTreesClassifier
|
|
5
|
+
from ....data_type import DataType
|
|
6
|
+
from ....predictor import Predictor
|
|
7
|
+
from ....dataset import Dataset
|
|
8
|
+
from ....candidate import Candidate
|
|
9
|
+
from ....decorators.all import is_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
13
|
+
class ActExtraTreesClassifier(Predictor):
|
|
14
|
+
"""[STEP] Extra Trees Classifier"""
|
|
15
|
+
|
|
16
|
+
name: str = "Extra Trees Classifier"
|
|
17
|
+
_description: str = textwrap.dedent('''\
|
|
18
|
+
ExtraTreesClassifier is a machine learning algorithm that makes
|
|
19
|
+
predictions by combining the outputs of multiple decision trees.''')
|
|
20
|
+
_description_long: str = textwrap.dedent('''\
|
|
21
|
+
ExtraTreesClassifier is a type of ensemble learning algorithm that
|
|
22
|
+
belongs to the family of decision tree-based models. It works by building multiple
|
|
23
|
+
decision trees, where each tree is trained on a random subset of the input feature
|
|
24
|
+
and a random subset of the training data. At prediction time, the algorithm aggregates
|
|
25
|
+
the outputs of all the decision trees to make a final prediction.''')
|
|
26
|
+
_usage: str = "Use when you want a low-tuning tabular classifier, stronger than ActDecisionTreeClassifier and simpler than ActBaggingClassifier. Applicable to numeric/categorical tabular data for binary or multiclass. Avoid when you need calibrated probabilities or very sparse text features."
|
|
27
|
+
refs: list[dict[str, Any]] = [
|
|
28
|
+
{
|
|
29
|
+
'year': 2006,
|
|
30
|
+
'name': 'Extremely randomized trees',
|
|
31
|
+
'authors': [
|
|
32
|
+
'Pierre Geurts',
|
|
33
|
+
'Damien Ernst',
|
|
34
|
+
'Louis Wehenkel'
|
|
35
|
+
],
|
|
36
|
+
'doi': 'https://doi.org/10.1007/s10994-006-6226-1',
|
|
37
|
+
'publisher': 'Machine Learning Vol. 63 page 3--42'
|
|
38
|
+
}
|
|
39
|
+
]
|
|
40
|
+
def __init__(self):
|
|
41
|
+
self.configuration = {
|
|
42
|
+
'max_depth': {
|
|
43
|
+
'description': 'Max depth of each tree',
|
|
44
|
+
'default': 15,
|
|
45
|
+
'range': [1, 100]
|
|
46
|
+
},
|
|
47
|
+
'min_samples_leaf': {
|
|
48
|
+
'description': 'The minimum number of samples required to be at a leaf node.',
|
|
49
|
+
'default': 1,
|
|
50
|
+
'range': [1, 15]
|
|
51
|
+
},
|
|
52
|
+
'min_samples_split': {
|
|
53
|
+
'description': 'The minimum number of samples required to split an internal node',
|
|
54
|
+
'default': 2,
|
|
55
|
+
'range': [2, 20]
|
|
56
|
+
},
|
|
57
|
+
'bootstrap': {
|
|
58
|
+
'description': textwrap.dedent('''\
|
|
59
|
+
Whether bootstrap samples are used when building trees. If
|
|
60
|
+
False, the whole dataset is used to build each tree.'''),
|
|
61
|
+
'default': False
|
|
62
|
+
},
|
|
63
|
+
'max_features': {
|
|
64
|
+
'description': 'The number of features to consider when looking for the best split',
|
|
65
|
+
'default': 'sqrt',
|
|
66
|
+
'categorical': ['sqrt', 'log2']
|
|
67
|
+
},
|
|
68
|
+
'criterion': {
|
|
69
|
+
'description': 'The function to measure the quality of a split.',
|
|
70
|
+
'default': "gini",
|
|
71
|
+
'categorical': ['gini', 'entropy']
|
|
72
|
+
},
|
|
73
|
+
'n_estimators': {
|
|
74
|
+
'description': 'Number of threes',
|
|
75
|
+
'default': 100,
|
|
76
|
+
'range': [1, 500]
|
|
77
|
+
},
|
|
78
|
+
'random_state': {
|
|
79
|
+
'description': 'random_state',
|
|
80
|
+
'default': 42
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
self.model: ExtraTreesClassifier = None
|
|
84
|
+
self.columns: list[str] = []
|
|
85
|
+
|
|
86
|
+
def _select_features(self, X):
|
|
87
|
+
if self.columns and hasattr(X, 'columns'):
|
|
88
|
+
return X[self.columns]
|
|
89
|
+
return X
|
|
90
|
+
|
|
91
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
92
|
+
self.columns = dataset.get_columns_names_by_type(DataType.NUMERIC)
|
|
93
|
+
if not self.columns:
|
|
94
|
+
self.columns = dataset.features
|
|
95
|
+
|
|
96
|
+
self.model = ExtraTreesClassifier(**self.passthrough_parameters())
|
|
97
|
+
self.model.fit(self._select_features(dataset.X), dataset.y)
|
|
98
|
+
return self
|
|
99
|
+
|
|
100
|
+
def predict(self, X):
|
|
101
|
+
return super().predict(self._select_features(X))
|
|
102
|
+
|
|
103
|
+
def predict_proba(self, X):
|
|
104
|
+
return super().predict_proba(self._select_features(X))
|
|
105
|
+
|
|
106
|
+
def score(self, X, y=None, *args, **kwargs):
|
|
107
|
+
return self.model.score(self._select_features(X), y, *args, **kwargs)
|
|
108
|
+
|
|
109
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
110
|
+
return dataset.type_of_target in \
|
|
111
|
+
['binary', 'multiclass', 'multilabel-indicator'] \
|
|
112
|
+
and bool(dataset.get_columns_names_by_type(DataType.NUMERIC))
|
|
113
|
+
|
|
114
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
115
|
+
return 0.5 # neutral
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""[STEP] Gaussian NB"""
|
|
2
|
+
|
|
3
|
+
import textwrap
|
|
4
|
+
from typing import Any
|
|
5
|
+
from sklearn.naive_bayes import GaussianNB
|
|
6
|
+
from ....predictor import Predictor
|
|
7
|
+
from ....dataset import Dataset
|
|
8
|
+
from ....candidate import Candidate
|
|
9
|
+
from ....decorators.all import is_step
|
|
10
|
+
|
|
11
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
12
|
+
class ActGaussianNb(Predictor):
|
|
13
|
+
"""[STEP] Gaussian NB"""
|
|
14
|
+
|
|
15
|
+
name: str = " Gaussian NB"
|
|
16
|
+
_description: str = textwrap.dedent('''\
|
|
17
|
+
GaussianNB is a machine learning algorithm that makes predictions
|
|
18
|
+
based on the Gaussian (normal) distribution of the input features.''')
|
|
19
|
+
_description_long: str = textwrap.dedent('''\
|
|
20
|
+
GaussianNB is a type of naive Bayes classifier that assumes the
|
|
21
|
+
input features are independent and follow a Gaussian (normal) distribution.
|
|
22
|
+
It uses Bayes' theorem to calculate the probability of each class given the
|
|
23
|
+
input features and then makes a prediction based on the highest probability.
|
|
24
|
+
GaussianNB is particularly useful when the input features have a continuous
|
|
25
|
+
distribution and can be modeled well by a normal distribution.
|
|
26
|
+
It is a simple and fast algorithm that works well for many classification problems,
|
|
27
|
+
especially when the number of features is much larger than the number of samples.''')
|
|
28
|
+
_usage: str = "Use when you need a fast baseline for continuous features; consider ActBernoulliNb for binary features or ActCatBoost for higher accuracy. Applicable to tabular binary/multiclass tasks with roughly normal feature distributions. Avoid when features are strongly dependent or mostly categorical."
|
|
29
|
+
refs: list[dict[str, Any]] = []
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
self.configuration = {
|
|
33
|
+
'var_smoothing': {
|
|
34
|
+
'description': textwrap.dedent('''\
|
|
35
|
+
Portion of the largest variance of all features that is
|
|
36
|
+
added to variances for calculation stability.'''),
|
|
37
|
+
'default': 1e-9,
|
|
38
|
+
'range': [1e-11, 1e-4]
|
|
39
|
+
},
|
|
40
|
+
}
|
|
41
|
+
self.model: GaussianNB = None
|
|
42
|
+
|
|
43
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
44
|
+
self.model = GaussianNB(**self.passthrough_parameters())
|
|
45
|
+
self.model.fit(dataset.X, dataset.y)
|
|
46
|
+
return self
|
|
47
|
+
|
|
48
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
49
|
+
return dataset.type_of_target in \
|
|
50
|
+
['binary', 'multiclass', 'multilabel-indicator']
|
|
51
|
+
|
|
52
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
53
|
+
return 0.5 # neutral
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"""[STEP] HistGradient Boosting Classifier"""
|
|
2
|
+
import textwrap
|
|
3
|
+
from typing import Any
|
|
4
|
+
from sklearn.ensemble import HistGradientBoostingClassifier
|
|
5
|
+
from ....predictor import Predictor
|
|
6
|
+
from ....dataset import Dataset
|
|
7
|
+
from ....candidate import Candidate
|
|
8
|
+
from ....data_type import DataType
|
|
9
|
+
from ....decorators.all import is_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
13
|
+
class ActHistGradientBoostingClassifier(Predictor):
|
|
14
|
+
"""[STEP] HistGradient Boosting Classifier"""
|
|
15
|
+
|
|
16
|
+
name: str = "HistGradient Boosting Classifier"
|
|
17
|
+
_description: str = textwrap.dedent('''\
|
|
18
|
+
HistGradientBoostingClassifier is a gradient boosting method that
|
|
19
|
+
uses histogram-based binning to speed up training on large datasets.''')
|
|
20
|
+
_description_long: str = textwrap.dedent('''\
|
|
21
|
+
HistGradientBoostingClassifier builds a sequence of decision trees using
|
|
22
|
+
histograms of feature values to reduce computation. It supports
|
|
23
|
+
regularization and early stopping to control overfitting while keeping
|
|
24
|
+
training fast on large datasets.''')
|
|
25
|
+
_usage: str = "Use when you want strong tabular accuracy on large numeric data; compare ActCatBoost for categorical-heavy data or ActExtraTreesClassifier for simpler ensembles. Applicable to binary, multiclass, or multilabel-indicator targets with numeric features. Avoid when features are mostly categorical or a simple baseline like ActDecisionTreeClassifier is preferred."
|
|
26
|
+
refs: list[dict[str, Any]] = [
|
|
27
|
+
{
|
|
28
|
+
'year': 2017,
|
|
29
|
+
'name': 'LightGBM: A Highly Efficient Gradient Boosting Decision Tree',
|
|
30
|
+
'authors': [
|
|
31
|
+
'Guolin Ke',
|
|
32
|
+
'Qi Meng',
|
|
33
|
+
'Thomas Finley',
|
|
34
|
+
'Taifeng Wang',
|
|
35
|
+
'Wei Chen',
|
|
36
|
+
'Weidong Ma',
|
|
37
|
+
'Qiwei Ye',
|
|
38
|
+
'Tie-Yan Liu'
|
|
39
|
+
],
|
|
40
|
+
'doi': 'https://doi.org/10.48550/arXiv.1712.01005',
|
|
41
|
+
'publisher': 'Advances in Neural Information Processing Systems 30 (NeurIPS 2017)'
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
def __init__(self):
|
|
46
|
+
self.configuration = {
|
|
47
|
+
'learning_rate': {
|
|
48
|
+
'description': 'The learning rate, also known as shrinkage.',
|
|
49
|
+
'default': 0.1,
|
|
50
|
+
'range': [0.01, 1.0]
|
|
51
|
+
},
|
|
52
|
+
'max_iter': {
|
|
53
|
+
'description': 'The maximum number of boosting iterations.',
|
|
54
|
+
'default': 100,
|
|
55
|
+
'range': [50, 500]
|
|
56
|
+
},
|
|
57
|
+
'max_leaf_nodes': {
|
|
58
|
+
'description': 'The maximum number of leaves for each tree.',
|
|
59
|
+
'default': 31,
|
|
60
|
+
'range': [3, 2048]
|
|
61
|
+
},
|
|
62
|
+
'max_depth': {
|
|
63
|
+
'description': 'The maximum depth of each tree.',
|
|
64
|
+
'default': None,
|
|
65
|
+
'categorical': [None, 3, 5, 10, 15]
|
|
66
|
+
},
|
|
67
|
+
'min_samples_leaf': {
|
|
68
|
+
'description': 'The minimum number of samples per leaf.',
|
|
69
|
+
'default': 20,
|
|
70
|
+
'range': [1, 200]
|
|
71
|
+
},
|
|
72
|
+
'l2_regularization': {
|
|
73
|
+
'description': 'The L2 regularization parameter.',
|
|
74
|
+
'default': 1e-10,
|
|
75
|
+
'range': [1e-10, 1.0]
|
|
76
|
+
},
|
|
77
|
+
'max_bins': {
|
|
78
|
+
'description': 'The maximum number of bins to use for continuous features.',
|
|
79
|
+
'default': 255,
|
|
80
|
+
'range': [16, 255]
|
|
81
|
+
},
|
|
82
|
+
'validation_fraction': {
|
|
83
|
+
'description': 'The proportion of data used for early stopping.',
|
|
84
|
+
'default': 0.1,
|
|
85
|
+
'range': [0.05, 0.3]
|
|
86
|
+
},
|
|
87
|
+
'n_iter_no_change': {
|
|
88
|
+
'description': 'Used to determine when to early stop.',
|
|
89
|
+
'default': 10,
|
|
90
|
+
'range': [2, 20]
|
|
91
|
+
},
|
|
92
|
+
'tol': {
|
|
93
|
+
'description': 'The absolute tolerance to use when comparing scores.',
|
|
94
|
+
'default': 1e-4,
|
|
95
|
+
'range': [1e-8, 1e-2]
|
|
96
|
+
},
|
|
97
|
+
'class_weight': {
|
|
98
|
+
'description': textwrap.dedent('''\
|
|
99
|
+
The "balanced" mode uses values of y to adjust weights inversely
|
|
100
|
+
proportional to class frequencies.'''),
|
|
101
|
+
'default': None,
|
|
102
|
+
'categorical': [None, 'balanced']
|
|
103
|
+
},
|
|
104
|
+
'random_state': {
|
|
105
|
+
'description': 'Random state for reproducibility.',
|
|
106
|
+
'default': 42
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
self.model: HistGradientBoostingClassifier = None
|
|
110
|
+
self.columns: list[str] = []
|
|
111
|
+
|
|
112
|
+
def _select_features(self, X):
|
|
113
|
+
if self.columns and hasattr(X, 'columns'):
|
|
114
|
+
return X[self.columns]
|
|
115
|
+
return X
|
|
116
|
+
|
|
117
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
118
|
+
self.columns = dataset.get_columns_names_by_type(DataType.NUMERIC)
|
|
119
|
+
if not self.columns:
|
|
120
|
+
self.columns = dataset.features
|
|
121
|
+
|
|
122
|
+
self.model = HistGradientBoostingClassifier(
|
|
123
|
+
early_stopping=True,
|
|
124
|
+
**self.passthrough_parameters()
|
|
125
|
+
)
|
|
126
|
+
self.model.fit(self._select_features(dataset.X), dataset.y)
|
|
127
|
+
return self
|
|
128
|
+
|
|
129
|
+
def predict(self, X):
|
|
130
|
+
return super().predict(self._select_features(X))
|
|
131
|
+
|
|
132
|
+
def predict_proba(self, X):
|
|
133
|
+
return super().predict_proba(self._select_features(X))
|
|
134
|
+
|
|
135
|
+
def score(self, X, y=None, *args, **kwargs):
|
|
136
|
+
return self.model.score(self._select_features(X), y, *args, **kwargs)
|
|
137
|
+
|
|
138
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
139
|
+
return dataset.type_of_target in \
|
|
140
|
+
['binary', 'multiclass', 'multilabel-indicator'] \
|
|
141
|
+
and bool(dataset.get_columns_names_by_type(DataType.NUMERIC))
|
|
142
|
+
|
|
143
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
144
|
+
return 0.5 # neutral
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
|
|
2
|
+
"""[STEP] KNN"""
|
|
3
|
+
import textwrap
|
|
4
|
+
from typing import Any
|
|
5
|
+
from sklearn.neighbors import KNeighborsClassifier
|
|
6
|
+
from ....predictor import Predictor
|
|
7
|
+
from ....candidate import Candidate
|
|
8
|
+
from ....dataset import Dataset
|
|
9
|
+
from ....decorators.all import is_step
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@is_step('predictor', 'tabular', 'classifier')
|
|
13
|
+
class ActKNN(Predictor):
|
|
14
|
+
"""[STEP] KNN"""
|
|
15
|
+
|
|
16
|
+
name: str = "KNN"
|
|
17
|
+
_usage: str = "Use when you want a simple distance-based baseline on small to medium data; compare ActDecisionTreeClassifier or ActCatBoost for stronger baselines. Applicable to tabular data with numeric features and meaningful distance metrics. Avoid when data is high-dimensional, very large, or needs fast prediction."
|
|
18
|
+
_description: str = textwrap.dedent('''\
|
|
19
|
+
KNeighborsClassifier is a machine learning algorithm that makes
|
|
20
|
+
predictions for classification tasks using k-nearest neighbors.''')
|
|
21
|
+
_description_long: str = textwrap.dedent('''\
|
|
22
|
+
KNeighborsClassifier is a type of instance-based learning
|
|
23
|
+
algorithm that makes predictions for new input features based on the labels
|
|
24
|
+
of the k-nearest neighbors in the training data.
|
|
25
|
+
It works by calculating the distance between the new input features and all
|
|
26
|
+
the training data, and then selecting the k-nearest neighbors based on that distance
|
|
27
|
+
The label for the new input features is then determined by a majority vote of the
|
|
28
|
+
labels of the k-nearest neighbors.''')
|
|
29
|
+
refs: list[dict[str, Any]] = [
|
|
30
|
+
{
|
|
31
|
+
'year': 1951,
|
|
32
|
+
'name': 'Discriminatory Analysis, Nonparametric Discrimination: Consistency Properties',
|
|
33
|
+
'authors': [
|
|
34
|
+
'Evelyn Fix',
|
|
35
|
+
'Joseph Lawson Hodges Jr.'
|
|
36
|
+
],
|
|
37
|
+
'doi': 'https://doi.org/10.2307/1403797',
|
|
38
|
+
'publisher': 'Technical Report 4, USAF School of Aviation Medicine, Randolph Field'
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
'year': 1967,
|
|
42
|
+
'name': 'Nearest neighbor pattern classification',
|
|
43
|
+
'authors': [
|
|
44
|
+
'Thomas M. Cover',
|
|
45
|
+
'Peter E. Hart'
|
|
46
|
+
],
|
|
47
|
+
'doi': 'https://doi.org/10.1109/TIT.1967.1053964',
|
|
48
|
+
'publisher': 'IEEE Transactions on Information Theory. 13: page 21--27'
|
|
49
|
+
}
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
def __init__(self):
|
|
53
|
+
self.configuration = {
|
|
54
|
+
'metric': {
|
|
55
|
+
'description': 'Can be minkowski or manhattan',
|
|
56
|
+
'default': 'minkowski',
|
|
57
|
+
'categorical': ['minkowski', 'manhattan']
|
|
58
|
+
},
|
|
59
|
+
'n_neighbors': {
|
|
60
|
+
'description': 'Number of neighbors',
|
|
61
|
+
'default': 5,
|
|
62
|
+
'range': [1, 200],
|
|
63
|
+
'passthrough': False
|
|
64
|
+
},
|
|
65
|
+
'weights': {
|
|
66
|
+
'description': 'Weight function used in prediction.',
|
|
67
|
+
'default': 'uniform',
|
|
68
|
+
'categorical': ['uniform', 'distance']
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
self.model: KNeighborsClassifier = None
|
|
72
|
+
|
|
73
|
+
def fit(self, dataset: Dataset): # pylint: disable=unused-argument
|
|
74
|
+
self.model = KNeighborsClassifier(
|
|
75
|
+
n_neighbors = min(self.get_config('n_neighbors'), dataset.X.shape[0]),
|
|
76
|
+
**self.passthrough_parameters()
|
|
77
|
+
)
|
|
78
|
+
self.model.fit(dataset.X, dataset.y)
|
|
79
|
+
return self
|
|
80
|
+
|
|
81
|
+
def suitable(self, dataset: Dataset) -> bool:
|
|
82
|
+
return dataset.type_of_target in \
|
|
83
|
+
['binary', 'multiclass', 'multilabel-indicator']
|
|
84
|
+
|
|
85
|
+
def priorize(self, candidate: Candidate = None) -> float:
|
|
86
|
+
return 0.5 # neutral
|