From e99e729c1264f93f71223648938c798eab2398ec Mon Sep 17 00:00:00 2001 From: alexmindset Date: Tue, 7 May 2024 16:34:30 +0300 Subject: [PATCH] Update black formatting --- insolver/interpretation/shap.py | 12 ++++++---- insolver/report/metrics.py | 18 +++++++++----- insolver/report/report.py | 24 ++++++++++++------- requirements-dev.txt | 2 +- ...ample - Rain in Australia Prediction.ipynb | 2 ++ .../Regression Example - US Accidents.ipynb | 1 + 6 files changed, 40 insertions(+), 19 deletions(-) diff --git a/insolver/interpretation/shap.py b/insolver/interpretation/shap.py index 448a943..de73368 100644 --- a/insolver/interpretation/shap.py +++ b/insolver/interpretation/shap.py @@ -22,8 +22,10 @@ def __init__(self, estimator, estimator_type='tree', data=None): self.estimator_type = estimator_type if self.estimator_type not in ['tree', 'linear']: - raise NotImplementedError(f''' - estimator_type {estimator_type} is not supported. Supported values are "tree" and "linear".''') + raise NotImplementedError( + f''' + estimator_type {estimator_type} is not supported. Supported values are "tree" and "linear".''' + ) self.explainer = ( TreeExplainer(self.estimator) @@ -75,8 +77,10 @@ def logit(x): # check type of instance if not isinstance(instance, np.ndarray) and not isinstance(instance, pd.Series): - raise TypeError(f''' - Type {type(instance)} is not supported. Supported types are numpy.ndarray and pandas.Series.''') + raise TypeError( + f''' + Type {type(instance)} is not supported. Supported types are numpy.ndarray and pandas.Series.''' + ) # get feature_names OR check shape and create features names if isinstance(instance, pd.Series): feature_names = list(instance.index) diff --git a/insolver/report/metrics.py b/insolver/report/metrics.py index 35c277c..3377a78 100644 --- a/insolver/report/metrics.py +++ b/insolver/report/metrics.py @@ -148,8 +148,10 @@ def _calc_metrics(y_true, y_pred, task, metrics_to_calc, x, exposure=None): elif isinstance(metrics_to_calc, list): functions_names = metrics_to_calc else: - raise TypeError(f'''{type(metrics_to_calc)} type of metrics_to_calc is not supported. - Must be "all", "main" or list.''') + raise TypeError( + f'''{type(metrics_to_calc)} type of metrics_to_calc is not supported. + Must be "all", "main" or list.''' + ) result['root_mean_square_error'] = np.sqrt(functions['mean_squared_error'](y_true, y_pred)) @@ -167,8 +169,10 @@ def _calc_metrics(y_true, y_pred, task, metrics_to_calc, x, exposure=None): elif isinstance(metrics_to_calc, list): functions_names = metrics_to_calc else: - raise TypeError(f'''{type(metrics_to_calc)} type of metrics_to_calc is not supported. - Must be "all", "main" or list.''') + raise TypeError( + f'''{type(metrics_to_calc)} type of metrics_to_calc is not supported. + Must be "all", "main" or list.''' + ) elif type_of_true == 'binary' and type_of_pred == 'continuous': functions_names = ( @@ -180,8 +184,10 @@ def _calc_metrics(y_true, y_pred, task, metrics_to_calc, x, exposure=None): for name in functions_names: if name not in functions.keys(): - raise NotImplementedError(f'''{name} metric name is not supported. Supported names for {task} task: - {functions.keys()}.''') + raise NotImplementedError( + f'''{name} metric name is not supported. Supported names for {task} task: + {functions.keys()}.''' + ) try: if name == 'gini_coef' and exposure: result[name] = functions[name](y_true, y_pred, x[exposure])[2] diff --git a/insolver/report/report.py b/insolver/report/report.py index 778bc04..44da56f 100644 --- a/insolver/report/report.py +++ b/insolver/report/report.py @@ -186,20 +186,24 @@ def __init__( self.y_test = y_test self.original_dataset = original_dataset else: - raise TypeError(f"""Wrong types of input data. + raise TypeError( + f"""Wrong types of input data. \rX_train {type(X_train)} must be pandas.DataFrame \ry_train {type(y_train)} must be pandas.Series \rX_test {type(X_test)} must be pandas.DataFrame \ry_test {type(y_test)} should be pandas.Series \rpredicted_train {type(self.predicted_train)} must be pandas.Series \rpredicted_test {type(self.predicted_test)} must be pandas.Series - \rpredicted_test {type(original_dataset)} must be pandas.DataFrame""") + \rpredicted_test {type(original_dataset)} must be pandas.DataFrame""" + ) self._directory = ntpath.dirname(inspect.getfile(Report)) # check columns if not sorted(X_train.columns.to_list()) == sorted(X_test.columns.to_list()): - raise KeyError(f'''Columns in X_train {sorted(X_train.columns.to_list())} - and X_test {sorted(X_test.columns.to_list())} are not the same.''') + raise KeyError( + f'''Columns in X_train {sorted(X_train.columns.to_list())} + and X_test {sorted(X_test.columns.to_list())} are not the same.''' + ) elif len(set(X_train.columns.to_list()).difference(original_dataset.columns.to_list())) > 0: s = set(X_train.columns.to_list()).difference(original_dataset.columns.to_list()) raise KeyError(f'''Columns from X_train {s} are missing from original_dataset.''') @@ -324,9 +328,11 @@ def _save_model_section(self, path, report_name): 'articles': [ { 'name': 'Coefficients', - 'parts': [f''' + 'parts': [ + f'''
- {features_importance}{_create_importance_charts()}
'''], + {features_importance}{_create_importance_charts()}''' + ], 'header': '', 'footer': features_importance_footer, 'icon': '', @@ -347,9 +353,11 @@ def _save_model_section(self, path, report_name): }, { 'name': 'Partial Dependence', - 'parts': [f''' + 'parts': [ + f'''
- {pdp_part}
'''], + {pdp_part}''' + ], 'header': '', 'footer': pdp_footer, 'icon': '', diff --git a/requirements-dev.txt b/requirements-dev.txt index 3821f9e..a9ecb8f 100644 --- a/requirements-dev.txt +++ b/requirements-dev.txt @@ -1,4 +1,4 @@ -black>=22.6.0 +black[jupyter]==24.4.2 mypy>=0.971 pre-commit>=2.19.0 pytest>=6.2.5 diff --git a/tutorials/Binary Classification Example - Rain in Australia Prediction.ipynb b/tutorials/Binary Classification Example - Rain in Australia Prediction.ipynb index e910ef9..b209628 100644 --- a/tutorials/Binary Classification Example - Rain in Australia Prediction.ipynb +++ b/tutorials/Binary Classification Example - Rain in Australia Prediction.ipynb @@ -1834,6 +1834,7 @@ ], "source": [ "%%time\n", + "\n", "igbm = show_results(InsolverGBMWrapper(backend='lightgbm', task='class', n_estimators=100), x, y)" ] }, @@ -1980,6 +1981,7 @@ ], "source": [ "%%time\n", + "\n", "igbm3 = show_results(InsolverGBMWrapper(backend='xgboost', task='class', n_estimators=100), x, y)" ] }, diff --git a/tutorials/Regression Example - US Accidents.ipynb b/tutorials/Regression Example - US Accidents.ipynb index 691881e..bf86c76 100644 --- a/tutorials/Regression Example - US Accidents.ipynb +++ b/tutorials/Regression Example - US Accidents.ipynb @@ -16,6 +16,7 @@ "outputs": [], "source": [ "%matplotlib inline\n", + "\n", "import numpy as np\n", "import pandas as pd\n", "import matplotlib.pyplot as plt\n",