diff --git a/benchmarks/analyse_rankings.py b/benchmarks/analyse_rankings.py index cc0f724..7898a2b 100644 --- a/benchmarks/analyse_rankings.py +++ b/benchmarks/analyse_rankings.py @@ -6,6 +6,7 @@ import matplotlib.pyplot as plt + def extract_just_ranking(dfile): """Extract ranking from an output file.""" ranks = [] diff --git a/outrank/__main__.py b/outrank/__main__.py index ad729aa..1ccc1d2 100644 --- a/outrank/__main__.py +++ b/outrank/__main__.py @@ -1,7 +1,6 @@ from __future__ import annotations import argparse -import json import logging from outrank.task_generators import outrank_task_generate_data_set diff --git a/outrank/algorithms/importance_estimator.py b/outrank/algorithms/importance_estimator.py index e37ba1c..56953c5 100644 --- a/outrank/algorithms/importance_estimator.py +++ b/outrank/algorithms/importance_estimator.py @@ -11,7 +11,8 @@ import pandas as pd from scipy.stats import pearsonr from sklearn.feature_selection import mutual_info_classif -from sklearn.linear_model import LogisticRegression, SGDClassifier +from sklearn.linear_model import LogisticRegression +from sklearn.linear_model import SGDClassifier from sklearn.metrics import adjusted_mutual_info_score from sklearn.model_selection import cross_val_score from sklearn.preprocessing import OneHotEncoder @@ -19,7 +20,6 @@ from outrank.core_utils import is_prior_heuristic - logger = logging.getLogger('syn-logger') logger.setLevel(logging.DEBUG) @@ -43,11 +43,11 @@ def sklearn_MI(vector_first: Any, vector_second: Any) -> float: def sklearn_surrogate( - vector_first: Any, vector_second: Any, X: Any, surrogate_model: str + vector_first: Any, vector_second: Any, X: Any, surrogate_model: str, ) -> float: - + clf = initialize_classifier(surrogate_model) - + transf = OneHotEncoder() # They do not commute, swap if needed @@ -67,7 +67,7 @@ def sklearn_surrogate( clf, X, vector_second, scoring='neg_log_loss', cv=num_folds, ) estimate_feature_importance = 1 + \ - np.median(estimate_feature_importance_list) + np.median(estimate_feature_importance_list) return estimate_feature_importance @@ -127,7 +127,7 @@ def get_importances_estimate_pairwise(combination, reference_model_features, arg X = tmp_df[reference_model_features].values estimate_feature_importance = sklearn_surrogate( - vector_first, vector_second, X, args.heuristic + vector_first, vector_second, X, args.heuristic, ) elif 'MI-numba' in args.heuristic: diff --git a/outrank/core_ranking.py b/outrank/core_ranking.py index 4befed0..91b8381 100644 --- a/outrank/core_ranking.py +++ b/outrank/core_ranking.py @@ -21,11 +21,12 @@ import pandas as pd import tqdm -from outrank.algorithms.importance_estimator import get_importances_estimate_pairwise -from outrank.algorithms.sketches.counting_counters_ordinary import PrimitiveConstrainedCounter -from outrank.algorithms.sketches.counting_ultiloglog import ( - HyperLogLogWCache as HyperLogLog, -) +from outrank.algorithms.importance_estimator import \ + get_importances_estimate_pairwise +from outrank.algorithms.sketches.counting_counters_ordinary import \ + PrimitiveConstrainedCounter +from outrank.algorithms.sketches.counting_ultiloglog import \ + HyperLogLogWCache as HyperLogLog from outrank.core_utils import BatchRankingSummary from outrank.core_utils import extract_features_from_reference_JSON from outrank.core_utils import generic_line_parser diff --git a/outrank/feature_transformations/feature_transformer_vault/__init__.py b/outrank/feature_transformations/feature_transformer_vault/__init__.py index dd6e518..14bea7a 100644 --- a/outrank/feature_transformations/feature_transformer_vault/__init__.py +++ b/outrank/feature_transformations/feature_transformer_vault/__init__.py @@ -2,9 +2,8 @@ from outrank.feature_transformations.feature_transformer_vault.default_transformers import DEFAULT_TRANSFORMERS from outrank.feature_transformations.feature_transformer_vault.default_transformers import MINIMAL_TRANSFORMERS -from outrank.feature_transformations.feature_transformer_vault.fw_transformers import ( - FW_TRANSFORMERS, -) +from outrank.feature_transformations.feature_transformer_vault.fw_transformers import \ + FW_TRANSFORMERS _tr_global_namespace = { 'default': DEFAULT_TRANSFORMERS, diff --git a/outrank/feature_transformations/feature_transformer_vault/default_transformers.py b/outrank/feature_transformations/feature_transformer_vault/default_transformers.py index 96d866c..705b910 100644 --- a/outrank/feature_transformations/feature_transformer_vault/default_transformers.py +++ b/outrank/feature_transformations/feature_transformer_vault/default_transformers.py @@ -1,5 +1,6 @@ # Some boilerplate transformations people tend to use from __future__ import annotations + MINIMAL_TRANSFORMERS = { '_tr_sqrt': 'np.sqrt(X)', '_tr_log(x+1)': 'np.log(X + 1)', diff --git a/outrank/feature_transformations/feature_transformer_vault/fw_transformers.py b/outrank/feature_transformations/feature_transformer_vault/fw_transformers.py index 81476c2..e1d8226 100644 --- a/outrank/feature_transformations/feature_transformer_vault/fw_transformers.py +++ b/outrank/feature_transformations/feature_transformer_vault/fw_transformers.py @@ -2,9 +2,8 @@ import numpy as np -from outrank.feature_transformations.feature_transformer_vault.default_transformers import ( - DEFAULT_TRANSFORMERS, -) +from outrank.feature_transformations.feature_transformer_vault.default_transformers import \ + DEFAULT_TRANSFORMERS FW_TRANSFORMERS = DEFAULT_TRANSFORMERS.copy() resolution_range = [1, 10, 50, 100] diff --git a/outrank/task_selftest.py b/outrank/task_selftest.py index cd1cb45..b28536c 100644 --- a/outrank/task_selftest.py +++ b/outrank/task_selftest.py @@ -1,5 +1,6 @@ # helper set of methods that enable anywhere verification of core functions from __future__ import annotations + import logging import os import shutil diff --git a/tests/fw_transformers_test.py b/tests/fw_transformers_test.py index f3c76be..1f43cc5 100644 --- a/tests/fw_transformers_test.py +++ b/tests/fw_transformers_test.py @@ -5,9 +5,8 @@ import numpy as np -from outrank.feature_transformations.feature_transformer_vault.fw_transformers import ( - FW_TRANSFORMERS, -) +from outrank.feature_transformations.feature_transformer_vault.fw_transformers import \ + FW_TRANSFORMERS sys.path.append('./outrank') diff --git a/tests/hll_test.py b/tests/hll_test.py index 8830778..0f32ea0 100644 --- a/tests/hll_test.py +++ b/tests/hll_test.py @@ -3,9 +3,8 @@ import sys import unittest -from outrank.algorithms.sketches.counting_ultiloglog import ( - HyperLogLogWCache as HyperLogLog, -) +from outrank.algorithms.sketches.counting_ultiloglog import \ + HyperLogLogWCache as HyperLogLog sys.path.append('./outrank') diff --git a/tests/mi_numba_test.py b/tests/mi_numba_test.py index ffd21de..a81f1cd 100644 --- a/tests/mi_numba_test.py +++ b/tests/mi_numba_test.py @@ -5,9 +5,8 @@ import numpy as np -from outrank.algorithms.feature_ranking.ranking_mi_numba import ( - mutual_info_estimator_numba, -) +from outrank.algorithms.feature_ranking.ranking_mi_numba import \ + mutual_info_estimator_numba np.random.seed(123) sys.path.append('./outrank') diff --git a/tests/ranking_module_test.py b/tests/ranking_module_test.py index fd99092..7c282f3 100644 --- a/tests/ranking_module_test.py +++ b/tests/ranking_module_test.py @@ -12,12 +12,10 @@ from outrank.core_ranking import compute_combined_features from outrank.core_ranking import get_combinations_from_columns from outrank.core_ranking import mixed_rank_graph -from outrank.feature_transformations.feature_transformer_vault import ( - default_transformers, -) -from outrank.feature_transformations.ranking_transformers import ( - FeatureTransformerGeneric, -) +from outrank.feature_transformations.feature_transformer_vault import \ + default_transformers +from outrank.feature_transformations.ranking_transformers import \ + FeatureTransformerGeneric sys.path.append('./outrank')