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,71 @@
|
|
|
1
|
+
"""[METRIC] F1 Score"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import f1_score
|
|
6
|
+
from sklearn.utils.multiclass import type_of_target as get_type_of_target
|
|
7
|
+
from ._classification import resolve_pos_label
|
|
8
|
+
from ..metric import Metric
|
|
9
|
+
|
|
10
|
+
class F1ScoreMetric(Metric):
|
|
11
|
+
"""[METRIC] F1 Score.
|
|
12
|
+
|
|
13
|
+
:param pos_label: Binary positive class. If None, use 1 for 0/1 or -1/1
|
|
14
|
+
labels, otherwise the last sorted class. Training labels passed to
|
|
15
|
+
compute as y_train take precedence for automatic class selection.
|
|
16
|
+
Ignored for multiclass and multilabel targets.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
name: str = 'F1 Score'
|
|
20
|
+
_description: str = textwrap.dedent('''\
|
|
21
|
+
F1 Score is a metric that combines precision and recall to
|
|
22
|
+
evaluate a model's performance. It is especially useful for imbalanced datasets,
|
|
23
|
+
providing a balance between false positives and false negatives.''')
|
|
24
|
+
_description_long: str = textwrap.dedent('''\
|
|
25
|
+
F1 Score measures a model's performance by combining precision
|
|
26
|
+
(the accuracy of positive predictions) and recall (the ability to identify all positive cases).
|
|
27
|
+
It is calculated as the harmonic mean of precision and recall, making it particularly useful in
|
|
28
|
+
healthcare when dealing with imbalanced data.
|
|
29
|
+
The F1 Score ranges from 0 to 1, where 1 indicates perfect precision and recall.
|
|
30
|
+
For example, if a model has a precision of 70% and a recall of 80%, the F1 Score would be
|
|
31
|
+
calculated as 2 * (0.70 * 0.80) / (0.70 + 0.80) = 0.74. This metric helps ensure that both false positives
|
|
32
|
+
and false negatives are considered, making it valuable for medical decision-making.''')
|
|
33
|
+
refs: list[dict[str, Any]] = [
|
|
34
|
+
{
|
|
35
|
+
'year': 2007,
|
|
36
|
+
'name': 'The truth of the F-measure',
|
|
37
|
+
'authors': [
|
|
38
|
+
'Yutaka Sasaki'
|
|
39
|
+
],
|
|
40
|
+
'doi': 'https://www.researchgate.net/publication/268185911_The_truth_of_the_F-measure',
|
|
41
|
+
'publisher': ' Teach Tutor Mater. Vol. 1, no. 5. pp. 1–5'
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
def __init__(self, pos_label: Any = None) -> None:
|
|
46
|
+
self.pos_label = pos_label
|
|
47
|
+
|
|
48
|
+
def __str__(self) -> str:
|
|
49
|
+
return 'f1_score'
|
|
50
|
+
|
|
51
|
+
def suitable(
|
|
52
|
+
self,
|
|
53
|
+
X: pd.DataFrame,
|
|
54
|
+
y: pd.DataFrame,
|
|
55
|
+
type_of_target: str) -> bool:
|
|
56
|
+
return type_of_target in ['binary', 'multiclass', 'multilabel-indicator']
|
|
57
|
+
|
|
58
|
+
def compute(
|
|
59
|
+
self,
|
|
60
|
+
y: pd.DataFrame,
|
|
61
|
+
y_pred:pd.DataFrame,
|
|
62
|
+
**kwargs) -> float:
|
|
63
|
+
y_train = kwargs.get('y_train')
|
|
64
|
+
match get_type_of_target(y if y_train is None else y_train):
|
|
65
|
+
case 'multiclass':
|
|
66
|
+
return f1_score(y, y_pred, average ='weighted')
|
|
67
|
+
case 'multilabel-indicator':
|
|
68
|
+
return f1_score(y, y_pred, average ='samples')
|
|
69
|
+
case _:
|
|
70
|
+
pos_label = resolve_pos_label(y, self.pos_label, y_train)
|
|
71
|
+
return f1_score(y, y_pred, pos_label=pos_label, zero_division=0.0)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""[METRIC] Integrated Brier Score for Survival Models"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
import numpy as np
|
|
6
|
+
from sksurv.metrics import integrated_brier_score
|
|
7
|
+
from ._survival_times import brier_evaluation_times
|
|
8
|
+
from ..metric import Metric
|
|
9
|
+
from ..dataset import Dataset
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class IntegratedBrierScoreMetric(Metric):
|
|
13
|
+
"""[METRIC] Integrated Brier Score for Survival Models"""
|
|
14
|
+
|
|
15
|
+
name: str = 'Integrated Brier Score'
|
|
16
|
+
greater_is_better = False
|
|
17
|
+
_description: str = textwrap.dedent('''\
|
|
18
|
+
The Integrated Brier Score (IBS) is a measure used to evaluate how well survival
|
|
19
|
+
models predict the likelihood of an event happening over time. It looks at the
|
|
20
|
+
difference between what the model predicts and what actually happens, including cases
|
|
21
|
+
where data is incomplete. A lower IBS score means the model is more accurate.''')
|
|
22
|
+
_description_long: str = textwrap.dedent('''\
|
|
23
|
+
The Integrated Brier Score (IBS) is a tool used to check how accurately survival models predict events,
|
|
24
|
+
like the time until a patient experiences a certain outcome. It compares the model's predictions with
|
|
25
|
+
real-life results over a period of time, taking into account situations where some data may be missing
|
|
26
|
+
or incomplete. By looking at these differences, the IBS provides a single score that summarizes the model's
|
|
27
|
+
performance. A lower IBS score indicates that the model is doing a better job at making accurate predictions,
|
|
28
|
+
which is important for making informed decisions in healthcare and research.''')
|
|
29
|
+
refs: list[dict[str, Any]] = [
|
|
30
|
+
{
|
|
31
|
+
'year': 1999,
|
|
32
|
+
'name': textwrap.dedent("""\
|
|
33
|
+
Assessment and comparison of prognostic classification schemes for survival data
|
|
34
|
+
"""),
|
|
35
|
+
'authors': [
|
|
36
|
+
'E. Graf',
|
|
37
|
+
'C. Schmoor',
|
|
38
|
+
'W. Sauerbrei',
|
|
39
|
+
'M. Schumacher'
|
|
40
|
+
],
|
|
41
|
+
'doi': textwrap.dedent("""\
|
|
42
|
+
https://doi.org/10.1002/(SICI)1097-0258(19990915/30)18:17/18%3C2529::AID-SIM274%3E3.0.CO;2-5
|
|
43
|
+
"""),
|
|
44
|
+
'publisher': ' Statistics in Medicine, vol. 18, no. 17-18, pp. 2529–2545'
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
def __str__(self) -> str:
|
|
49
|
+
return 'integrated_brier_score'
|
|
50
|
+
|
|
51
|
+
@property
|
|
52
|
+
def needed_prediction(self) -> str:
|
|
53
|
+
return 'predict_survival_function'
|
|
54
|
+
|
|
55
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
56
|
+
return type_of_target == 'survival'
|
|
57
|
+
|
|
58
|
+
def compute(
|
|
59
|
+
self,
|
|
60
|
+
y: pd.DataFrame,
|
|
61
|
+
y_pred: pd.DataFrame,
|
|
62
|
+
y_train: pd.DataFrame = None,
|
|
63
|
+
**kwargs) -> float:
|
|
64
|
+
"""Compute the Integrated Brier Score (IBS) with the predicted data.
|
|
65
|
+
|
|
66
|
+
Integrate over a 100-point evenly spaced grid over
|
|
67
|
+
[min(test time), max(test time)), after limiting follow-up to the
|
|
68
|
+
training horizon. At least two distinct evaluation times are required.
|
|
69
|
+
|
|
70
|
+
:param pd.DataFrame y: Ground truth data (duration and event status).
|
|
71
|
+
:param y_pred: Predicted survival probability functions, one per sample.
|
|
72
|
+
:param pd.DataFrame y_train: Training data (duration and event status).
|
|
73
|
+
:param dict, optional \\**kwargs: Additional parameters
|
|
74
|
+
:return: Computed value
|
|
75
|
+
"""
|
|
76
|
+
y_train_samples = Dataset.normalize_survival_target(y_train)
|
|
77
|
+
y_samples = Dataset.fix_y_survival(y, y_train_samples)
|
|
78
|
+
|
|
79
|
+
y_train_struct = np.array(
|
|
80
|
+
y_train_samples,
|
|
81
|
+
dtype=[('event', 'bool'), ('time', 'float')]
|
|
82
|
+
)
|
|
83
|
+
y_struct = np.array(
|
|
84
|
+
y_samples,
|
|
85
|
+
dtype=[('event', 'bool'), ('time', 'float')]
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
times = brier_evaluation_times(y_struct['time'])
|
|
89
|
+
if times.size < 2:
|
|
90
|
+
raise ValueError(
|
|
91
|
+
"Integrated Brier score requires at least two distinct evaluation times."
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
# Evaluate survival probabilities on the same grid for every sample.
|
|
95
|
+
predictions = np.asarray([[fn(t) for t in times] for fn in y_pred])
|
|
96
|
+
|
|
97
|
+
# Calculate integrated Brier score using sksurv function
|
|
98
|
+
return integrated_brier_score(y_train_struct, y_struct, predictions, times)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""[METRIC] Integrated Brier Score Loss for Survival Models"""
|
|
2
|
+
import textwrap
|
|
3
|
+
import pandas as pd
|
|
4
|
+
from .integrated_brier_score import IntegratedBrierScoreMetric
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class IntegratedBrierScoreLossMetric(IntegratedBrierScoreMetric):
|
|
8
|
+
"""[METRIC] Integrated Brier Score Loss for Survival Models"""
|
|
9
|
+
|
|
10
|
+
name: str = 'Reverse Integrated Brier Score'
|
|
11
|
+
greater_is_better = True # This metric returns 1 - IBS.
|
|
12
|
+
_description: str = textwrap.dedent('''\
|
|
13
|
+
The Integrated Brier Score (IBS) is a measure used to evaluate how well survival
|
|
14
|
+
models predict the likelihood of an event happening over time. Here we compute 1 - IBS''')
|
|
15
|
+
_description_long: str = textwrap.dedent('''\
|
|
16
|
+
The Integrated Brier Score (IBS) is a tool used to check how accurately survival models predict events,
|
|
17
|
+
like the time until a patient experiences a certain outcome. It compares the model's predictions with
|
|
18
|
+
real-life results over a period of time, taking into account situations where some data may be missing
|
|
19
|
+
or incomplete. By looking at these differences, the IBS provides a single score that summarizes the model's
|
|
20
|
+
performance. A lower IBS score indicates that the model is doing a better job at making accurate predictions,
|
|
21
|
+
which is important for making informed decisions in healthcare and research. Here we compute 1 - IBS
|
|
22
|
+
''')
|
|
23
|
+
|
|
24
|
+
def __str__(self) -> str:
|
|
25
|
+
return 'integrated_brier_score_loss'
|
|
26
|
+
|
|
27
|
+
def compute(
|
|
28
|
+
self,
|
|
29
|
+
y: pd.DataFrame,
|
|
30
|
+
y_pred: pd.DataFrame,
|
|
31
|
+
y_train: pd.DataFrame = None,
|
|
32
|
+
**kwargs) -> float:
|
|
33
|
+
"""Compute the Integrated Brier Score Loss (IBS) with the predicted data.
|
|
34
|
+
|
|
35
|
+
:param pd.DataFrame y: Ground truth data (duration and event status).
|
|
36
|
+
:param pd.DataFrame y_pred: Predicted data (risk scores or predicted survival times).
|
|
37
|
+
:param pd.DataFrame y_train: Training data (duration and event status).
|
|
38
|
+
:param dict, optional \\**kwargs: Additional parameters
|
|
39
|
+
:return: Computed value
|
|
40
|
+
"""
|
|
41
|
+
return 1 - super().compute(y, y_pred, y_train, **kwargs)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""[METRIC] Mean Absolute Error"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import mean_absolute_error
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
class MeanAbsoluteErrorMetric(Metric):
|
|
9
|
+
"""[METRIC] Mean Absolute Error"""
|
|
10
|
+
|
|
11
|
+
name: str = 'Mean Absolute Error'
|
|
12
|
+
greater_is_better = False
|
|
13
|
+
_description: str = textwrap.dedent('''\
|
|
14
|
+
Mean Absolute Error (MAE) evaluates the accuracy of a predictive model by calculating
|
|
15
|
+
the average of the absolute differences between predicted and actual values. It is a simple and intuitive metric
|
|
16
|
+
that helps understand how far off predictions are from the true outcomes.''')
|
|
17
|
+
_description_long: str = textwrap.dedent('''\
|
|
18
|
+
Mean Absolute Error (MAE) evaluates a model's accuracy by calculating the average of the absolute differences
|
|
19
|
+
between predicted and actual values. It provides a clear understanding of how far predictions are from true outcomes.
|
|
20
|
+
To calculate MAE, you sum the absolute errors (the differences between predicted and actual values) and divide by the
|
|
21
|
+
total number of predictions. For example, if the errors are 2, -3, and 1, the MAE would be (|2| + |-3| + |1|) / 3 = 2.
|
|
22
|
+
This metric is valuable in healthcare for assessing the accuracy of continuous predictions, like estimating patient
|
|
23
|
+
outcomes.''')
|
|
24
|
+
refs: list[dict[str, Any]] = [
|
|
25
|
+
{
|
|
26
|
+
'year': 2005,
|
|
27
|
+
'name': textwrap.dedent("""\
|
|
28
|
+
Advantages of the mean absolute error (MAE) over the root mean square error
|
|
29
|
+
(RMSE) in assessing average model performance"""),
|
|
30
|
+
'authors': [
|
|
31
|
+
'Willmott, Cort J',
|
|
32
|
+
'Matsuura, Kenji'
|
|
33
|
+
],
|
|
34
|
+
'doi': 'https://doi.org/10.3354%2Fcr030079',
|
|
35
|
+
'publisher': ' Climate Research. 30: 79-82'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return 'mean_absolute_error'
|
|
41
|
+
|
|
42
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
43
|
+
return type_of_target == 'continuous'
|
|
44
|
+
|
|
45
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
46
|
+
return mean_absolute_error(y, y_pred)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"""[METRIC] Mean Squared Error"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import mean_squared_error
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MeanSquaredErrorMetric(Metric):
|
|
10
|
+
"""[METRIC] Mean Squared Error"""
|
|
11
|
+
|
|
12
|
+
name: str = 'Mean Squared Error'
|
|
13
|
+
greater_is_better = False
|
|
14
|
+
_description: str = textwrap.dedent('''\
|
|
15
|
+
Mean Squared Error (MSE) measures the average of the squares of the errors
|
|
16
|
+
in predictions. It emphasizes larger errors, making it useful for assessing prediction accuracy.
|
|
17
|
+
''')
|
|
18
|
+
_description_long: str = textwrap.dedent('''\
|
|
19
|
+
Mean Squared Error (MSE) evaluates a model's accuracy by calculating the average of the squared
|
|
20
|
+
differences between predicted and actual values. It gives more weight to larger errors, which is important in healthcare.
|
|
21
|
+
To calculate MSE, you square each error, sum them, and divide by the total number of predictions.
|
|
22
|
+
For example, if the errors are 2, -3, and 1, the MSE would be (2² + (-3)² + 1²) / 3 = 4.67.
|
|
23
|
+
This metric helps identify how well a model performs, especially when larger errors matter more.
|
|
24
|
+
''')
|
|
25
|
+
refs: list[dict[str, Any]] = [
|
|
26
|
+
{
|
|
27
|
+
'year': 2006,
|
|
28
|
+
'name': 'Mathematical Statistics: Basic Ideas and Selected Topics',
|
|
29
|
+
'authors': [
|
|
30
|
+
'Bickel, Peter J'
|
|
31
|
+
],
|
|
32
|
+
'doi': 'https://doi.org/10.1201/9781315369266',
|
|
33
|
+
'publisher': textwrap.dedent("""\
|
|
34
|
+
Mathematical Statistics: Basic Ideas and Selected Topics. Vol. I (Second ed.). p. 20
|
|
35
|
+
""")
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return 'mean_squared_error'
|
|
41
|
+
|
|
42
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
43
|
+
return type_of_target == 'continuous'
|
|
44
|
+
|
|
45
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
46
|
+
return mean_squared_error(y, y_pred)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"""[METRIC] Mean Squared Log Error"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
from sklearn.metrics import mean_squared_log_error
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MeanSquaredLogErrorMetric(Metric):
|
|
10
|
+
"""[METRIC] Mean Squared Log Error"""
|
|
11
|
+
name: str = 'Mean Squared Log Error'
|
|
12
|
+
greater_is_better = False
|
|
13
|
+
_description: str = textwrap.dedent('''\
|
|
14
|
+
Mean Squared Log Error (MSLE) measures the average of the squared differences
|
|
15
|
+
between the logarithm of predicted and actual values. It is useful for data with wide-ranging values.
|
|
16
|
+
''')
|
|
17
|
+
_description_long: str = textwrap.dedent('''\
|
|
18
|
+
Mean Squared Log Error (MSLE) evaluates a model's accuracy by calculating the
|
|
19
|
+
average of the squared differences between the logarithms of predicted and actual values.
|
|
20
|
+
This metric is helpful when the target variable varies greatly in scale.
|
|
21
|
+
To calculate MSLE, you take the logarithm of both predicted and actual values, find the differences,
|
|
22
|
+
square them, and then average these squared differences. This approach reduces the impact of large errors,
|
|
23
|
+
making it valuable for assessing model performance in cases where relative differences matter more than
|
|
24
|
+
absolute differences.''')
|
|
25
|
+
refs: list[dict[str, Any]] = [
|
|
26
|
+
{
|
|
27
|
+
'year': 2021,
|
|
28
|
+
'name': 'Mean Squared Error, Deconstructed',
|
|
29
|
+
'authors': [
|
|
30
|
+
'Timothy O. Hodson',
|
|
31
|
+
'Thomas M. Over',
|
|
32
|
+
'Sydney Foks'
|
|
33
|
+
],
|
|
34
|
+
'doi': 'http://dx.doi.org/10.1029/2021MS002681',
|
|
35
|
+
'publisher': ' Journal of Advances in Modeling Earth Systems, volume 13'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return 'mean_squared_log_error'
|
|
41
|
+
|
|
42
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
43
|
+
return type_of_target == 'continuous' and not (y < 0).any(axis=None)
|
|
44
|
+
|
|
45
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float | None:
|
|
46
|
+
try:
|
|
47
|
+
return mean_squared_log_error(y, y_pred)
|
|
48
|
+
except: # pylint: disable=bare-except
|
|
49
|
+
return None
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"""[METRIC] Median Absolute Error"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import median_absolute_error
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class MedianAbsoluteErrorMetric(Metric):
|
|
10
|
+
"""[METRIC] Median Absolute Error"""
|
|
11
|
+
|
|
12
|
+
name: str = "Median Absolute Error"
|
|
13
|
+
greater_is_better = False
|
|
14
|
+
_description: str = textwrap.dedent('''\
|
|
15
|
+
Median Absolute Error (MedAE) is a metric used to evaluate the accuracy of a regression model.
|
|
16
|
+
It measures the median of the absolute differences between predicted values and actual values,
|
|
17
|
+
providing a robust indication of prediction errors.
|
|
18
|
+
''')
|
|
19
|
+
_description_long: str = textwrap.dedent('''\
|
|
20
|
+
Median Absolute Error (MedAE) is a metric that helps assess the accuracy of a regression
|
|
21
|
+
model by focusing on the errors in predictions. It calculates the absolute differences between the predicted values
|
|
22
|
+
and the actual values, then finds the median of these differences. This approach makes MedAE less sensitive to outliers
|
|
23
|
+
compared to other error metrics, as it focuses on the middle value of the errors. A lower MedAE indicates better model
|
|
24
|
+
performance, meaning the predictions are closer to the actual values. In summary, MedAE is a useful measure for
|
|
25
|
+
understanding the typical prediction error of a regression model.
|
|
26
|
+
''')
|
|
27
|
+
refs: list[dict[str, Any]] = [
|
|
28
|
+
{
|
|
29
|
+
'year': 1992,
|
|
30
|
+
'name': 'Error measures for generalizing about forecasting methods: ' \
|
|
31
|
+
'Empirical comparisons',
|
|
32
|
+
'authors': [
|
|
33
|
+
'Scott Armstrong',
|
|
34
|
+
'Fred Collopy'
|
|
35
|
+
],
|
|
36
|
+
'doi': 'https://doi.org/10.1016/j.neucom.2015.12.114',
|
|
37
|
+
'publisher': 'International Journal of Forecasting, ' \
|
|
38
|
+
'Volume 8, Issue 1, June 1992, Pages 69-80'
|
|
39
|
+
}
|
|
40
|
+
]
|
|
41
|
+
def __str__(self) -> str:
|
|
42
|
+
return 'median_absolute_error'
|
|
43
|
+
|
|
44
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
45
|
+
return type_of_target == 'continuous'
|
|
46
|
+
|
|
47
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
48
|
+
return median_absolute_error(y, y_pred)
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"""[METRIC] Precision"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import precision_score
|
|
6
|
+
from sklearn.utils.multiclass import type_of_target as get_type_of_target
|
|
7
|
+
from ._classification import resolve_pos_label
|
|
8
|
+
from ..metric import Metric
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class PrecisionMetric(Metric):
|
|
12
|
+
"""[METRIC] Precision.
|
|
13
|
+
|
|
14
|
+
:param pos_label: Binary positive class. If None, use 1 for 0/1 or -1/1
|
|
15
|
+
labels, otherwise the last sorted class. Training labels passed to
|
|
16
|
+
compute as y_train take precedence for automatic class selection.
|
|
17
|
+
Ignored for multiclass and multilabel targets.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
name: str = "Precision"
|
|
21
|
+
_description: str = textwrap.dedent('''\
|
|
22
|
+
Precision measures the accuracy of positive predictions made by a model.
|
|
23
|
+
It indicates the proportion of true positive results among all positive predictions.
|
|
24
|
+
''')
|
|
25
|
+
_description_long: str = textwrap.dedent('''\
|
|
26
|
+
Precision evaluates how many of the predicted positive cases are actually correct.
|
|
27
|
+
It is calculated as the number of true positives divided by the sum of true positives and false positives.
|
|
28
|
+
For example, if a model predicts 10 positive cases, and 7 of them are correct, the precision would be 70%.
|
|
29
|
+
This metric is important in healthcare to ensure that positive predictions are reliable, minimizing false alarms.
|
|
30
|
+
''')
|
|
31
|
+
refs: list[dict[str, Any]] = [
|
|
32
|
+
{
|
|
33
|
+
'year': 2007,
|
|
34
|
+
'name': textwrap.dedent("""\
|
|
35
|
+
Evaluation: From Precision, Recall and F-Measure to ROC, Informedness, Markedness & Correlation
|
|
36
|
+
"""),
|
|
37
|
+
'authors': [
|
|
38
|
+
'David M. W. Powers'
|
|
39
|
+
],
|
|
40
|
+
'doi': 'https://doi.org/10.48550/arXiv.2010.16061',
|
|
41
|
+
'publisher': 'Journal of Machine Learning Technologies'
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
def __init__(self, pos_label: Any = None) -> None:
|
|
46
|
+
self.pos_label = pos_label
|
|
47
|
+
|
|
48
|
+
def __str__(self) -> str:
|
|
49
|
+
return 'precision'
|
|
50
|
+
|
|
51
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
52
|
+
return type_of_target in ['binary', 'multiclass', 'multilabel-indicator']
|
|
53
|
+
|
|
54
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
55
|
+
y_train = kwargs.get('y_train')
|
|
56
|
+
match get_type_of_target(y if y_train is None else y_train):
|
|
57
|
+
case 'multiclass':
|
|
58
|
+
return precision_score(y, y_pred, average = 'weighted', zero_division=0.0)
|
|
59
|
+
case 'multilabel-indicator':
|
|
60
|
+
return precision_score(y, y_pred, average= 'samples', zero_division=0.0)
|
|
61
|
+
case _:
|
|
62
|
+
pos_label = resolve_pos_label(y, self.pos_label, y_train)
|
|
63
|
+
return precision_score(y, y_pred, pos_label=pos_label, zero_division=0.0)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"""[METRIC] R2 Score"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import r2_score
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class R2ScoreMetric(Metric):
|
|
10
|
+
"""[METRIC] R2 Score"""
|
|
11
|
+
|
|
12
|
+
name: str = "R2 Score"
|
|
13
|
+
_description: str = textwrap.dedent('''\
|
|
14
|
+
R² Score, or R-squared, measures how well a model explains the variability of the target variable.
|
|
15
|
+
It indicates the proportion of variance in the data that is predictable from the model.''')
|
|
16
|
+
_description_long: str = textwrap.dedent('''\
|
|
17
|
+
R² Score evaluates the goodness of fit of a regression model. It ranges from 0 to 1,
|
|
18
|
+
where 1 means the model perfectly explains the variability of the target variable, and 0 means it does not
|
|
19
|
+
explain any variability. To calculate R², you compare the model's predictions to the mean of the actual values.
|
|
20
|
+
For example, an R² of 0.80 means that 80% of the variance in the target variable is explained by the model.
|
|
21
|
+
This metric is useful in healthcare to assess how well a model predicts outcomes.''')
|
|
22
|
+
refs: list[dict[str, Any]] = [
|
|
23
|
+
{
|
|
24
|
+
'year': 1985,
|
|
25
|
+
'name': 'Cautionary Note about R2',
|
|
26
|
+
'authors': [
|
|
27
|
+
'Robert G. D. Steel',
|
|
28
|
+
'James H. Torrie'
|
|
29
|
+
],
|
|
30
|
+
'doi': 'https://doi.org/10.2307/2287561',
|
|
31
|
+
'publisher': textwrap.dedent("""\
|
|
32
|
+
The American Statistician, Vol. 39, No. 4, Part 1 (Nov., 1985),
|
|
33
|
+
wpp. 279-285 (7 pages)
|
|
34
|
+
""")
|
|
35
|
+
}
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
def __str__(self) -> Any:
|
|
39
|
+
return 'r2_score'
|
|
40
|
+
|
|
41
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
42
|
+
return type_of_target == 'continuous'
|
|
43
|
+
|
|
44
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
45
|
+
return r2_score(y, y_pred)
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""[METRIC] Recall"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
import pandas as pd
|
|
5
|
+
from sklearn.metrics import recall_score
|
|
6
|
+
from sklearn.utils.multiclass import type_of_target as get_type_of_target
|
|
7
|
+
from ._classification import resolve_pos_label
|
|
8
|
+
from ..metric import Metric
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class RecallMetric(Metric):
|
|
12
|
+
"""[METRIC] Recall.
|
|
13
|
+
|
|
14
|
+
:param pos_label: Binary positive class. If None, use 1 for 0/1 or -1/1
|
|
15
|
+
labels, otherwise the last sorted class. Training labels passed to
|
|
16
|
+
compute as y_train take precedence for automatic class selection.
|
|
17
|
+
Ignored for multiclass and multilabel targets.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
name: str = "Recall"
|
|
21
|
+
_description: str = textwrap.dedent('''\
|
|
22
|
+
Recall measures the ability of a model to identify all relevant positive cases.
|
|
23
|
+
It indicates the proportion of true positive results among all actual positive cases.
|
|
24
|
+
''')
|
|
25
|
+
_description_long: str = textwrap.dedent('''\
|
|
26
|
+
Recall evaluates how many actual positive cases were correctly predicted by the model.
|
|
27
|
+
It is calculated as the number of true positives divided by the total number of actual positives
|
|
28
|
+
(true positives + false negatives). For example, if there are 100 actual positive cases and the model
|
|
29
|
+
identifies 80, the recall would be 80 / (80 + 20) = 0.80 or 80%.
|
|
30
|
+
This metric is crucial in healthcare to ensure that positive cases are detected, reducing missed diagnoses.
|
|
31
|
+
''')
|
|
32
|
+
refs: list[dict[str, Any]] = [
|
|
33
|
+
{
|
|
34
|
+
'year': 2007,
|
|
35
|
+
'name': textwrap.dedent("""\
|
|
36
|
+
Evaluation: From Precision, Recall and F-Measure to ROC,
|
|
37
|
+
Informedness, Markedness & Correlation
|
|
38
|
+
"""),
|
|
39
|
+
'authors': [
|
|
40
|
+
'David M. W. Powers'
|
|
41
|
+
],
|
|
42
|
+
'doi': 'https://doi.org/10.48550/arXiv.2010.16061',
|
|
43
|
+
'publisher': 'Journal of Machine Learning Technologies'
|
|
44
|
+
}
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
def __init__(self, pos_label: Any = None) -> None:
|
|
48
|
+
self.pos_label = pos_label
|
|
49
|
+
|
|
50
|
+
def __str__(self) -> str:
|
|
51
|
+
return 'recall'
|
|
52
|
+
|
|
53
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
54
|
+
return type_of_target in ['binary', 'multiclass', 'multilabel-indicator']
|
|
55
|
+
|
|
56
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
57
|
+
y_train = kwargs.get('y_train')
|
|
58
|
+
match get_type_of_target(y if y_train is None else y_train):
|
|
59
|
+
case 'multiclass':
|
|
60
|
+
return recall_score(y, y_pred, average = 'weighted', zero_division=0.0)
|
|
61
|
+
case 'multilabel-indicator':
|
|
62
|
+
return recall_score(y, y_pred, average= 'samples', zero_division=0.0)
|
|
63
|
+
case _:
|
|
64
|
+
pos_label = resolve_pos_label(y, self.pos_label, y_train)
|
|
65
|
+
return recall_score(y, y_pred, pos_label=pos_label, zero_division=0.0)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""[METRIC] ROC AUC"""
|
|
2
|
+
from typing import Any
|
|
3
|
+
import textwrap
|
|
4
|
+
from sklearn.metrics import roc_auc_score
|
|
5
|
+
import pandas as pd
|
|
6
|
+
from ..metric import Metric
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class RocAucMetric(Metric):
|
|
10
|
+
"""[METRIC] ROC AUC"""
|
|
11
|
+
|
|
12
|
+
name: str = "ROC AUC"
|
|
13
|
+
_description: str = textwrap.dedent('''\
|
|
14
|
+
The ROC AUC metric (Receiver Operating Characteristic - Area Under the Curve) is a tool used to evaluate
|
|
15
|
+
the performance of a classification model. It measures the model's ability to distinguish between two
|
|
16
|
+
classes by indicating the proportion of true positives relative to false positives.''')
|
|
17
|
+
_description_long: str = textwrap.dedent('''\
|
|
18
|
+
The ROC AUC metric is a method that helps assess the effectiveness of a classification model.
|
|
19
|
+
The ROC curve illustrates the model's performance at various decision thresholds, with a curve closer
|
|
20
|
+
to the top-left corner indicating better performance. The AUC, or "area under the curve," provides
|
|
21
|
+
a score between 0 and 1, where 1 means perfect predictions and 0.5 means the model is no better than
|
|
22
|
+
random guessing. In essence, the ROC AUC metric is a clear way to evaluate a
|
|
23
|
+
model's ability to correctly distinguish between two categories.''')
|
|
24
|
+
refs: list[dict[str, Any]] = [
|
|
25
|
+
{
|
|
26
|
+
'year': 1982,
|
|
27
|
+
'name': textwrap.dedent("""\
|
|
28
|
+
The meaning and use of the area under a receiver operating characteristic (ROC) curve.
|
|
29
|
+
"""),
|
|
30
|
+
'authors': [
|
|
31
|
+
'Hanley James A.',
|
|
32
|
+
'McNeil Barbara J.'
|
|
33
|
+
],
|
|
34
|
+
'doi': 'https://doi.org/10.1148%2Fradiology.143.1.7063747',
|
|
35
|
+
'publisher': 'Radiology. 143 (1): 29-36.'
|
|
36
|
+
}
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
def __str__(self) -> str:
|
|
40
|
+
return 'ROC AUC'
|
|
41
|
+
|
|
42
|
+
def suitable(self, X: pd.DataFrame, y: pd.DataFrame, type_of_target: str) -> bool:
|
|
43
|
+
return type_of_target == 'binary'
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def needed_prediction(self) -> str:
|
|
47
|
+
return 'predict_proba'
|
|
48
|
+
|
|
49
|
+
def compute(self, y: pd.DataFrame, y_pred: pd.DataFrame, **kwargs) -> float:
|
|
50
|
+
return roc_auc_score(y, y_pred[:, 1])
|