From d89d79bffb3fcaf9fac68a4c8610d44edc0deac1 Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 19:52:01 -0500 Subject: [PATCH 1/8] Add nips2021 paper directory ... --- paper/{ => joss2021}/clf_metrics.png | Bin paper/{ => joss2021}/paper.bib | 0 paper/{ => joss2021}/paper.md | 0 paper/{ => joss2021}/reg_metrics.png | Bin 4 files changed, 0 insertions(+), 0 deletions(-) rename paper/{ => joss2021}/clf_metrics.png (100%) rename paper/{ => joss2021}/paper.bib (100%) rename paper/{ => joss2021}/paper.md (100%) rename paper/{ => joss2021}/reg_metrics.png (100%) diff --git a/paper/clf_metrics.png b/paper/joss2021/clf_metrics.png similarity index 100% rename from paper/clf_metrics.png rename to paper/joss2021/clf_metrics.png diff --git a/paper/paper.bib b/paper/joss2021/paper.bib similarity index 100% rename from paper/paper.bib rename to paper/joss2021/paper.bib diff --git a/paper/paper.md b/paper/joss2021/paper.md similarity index 100% rename from paper/paper.md rename to paper/joss2021/paper.md diff --git a/paper/reg_metrics.png b/paper/joss2021/reg_metrics.png similarity index 100% rename from paper/reg_metrics.png rename to paper/joss2021/reg_metrics.png From 1bfc1863d2a2d8e9437095ee4fcd79ba9085ba01 Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:15:39 -0500 Subject: [PATCH 2/8] Update binarymetrics plot ... --- slickml/metrics.py | 10 ++++++++-- slickml/plotting.py | 11 +++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/slickml/metrics.py b/slickml/metrics.py index 9a62fb8..1e9301c 100644 --- a/slickml/metrics.py +++ b/slickml/metrics.py @@ -536,7 +536,7 @@ def _average_methods(self): """ return ["binary", "weighted", "macro", "micro"] - def plot(self, figsize=None): + def plot(self, figsize=None, save_path=None): """Function to plot binary classification metrics. This function is a helper function based on the plotting_dict attribute of the BinaryClassificationMetrics class. @@ -545,9 +545,15 @@ def plot(self, figsize=None): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ - plot_binary_classification_metrics(figsize, **self.plotting_dict_) + plot_binary_classification_metrics(figsize=figsize, + save_path=save_path, + **self.plotting_dict_) class RegressionMetrics: diff --git a/slickml/plotting.py b/slickml/plotting.py index 04c38ac..a44a192 100644 --- a/slickml/plotting.py +++ b/slickml/plotting.py @@ -17,7 +17,7 @@ display(HTML("")) -def plot_binary_classification_metrics(figsize=None, **kwargs): +def plot_binary_classification_metrics(figsize=None, save_path=None, **kwargs): """ Function to plot binary classification metrics. This function is a helper function based on the plotting_dict @@ -27,6 +27,10 @@ def plot_binary_classification_metrics(figsize=None, **kwargs): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -229,6 +233,9 @@ def plot_binary_classification_metrics(figsize=None, **kwargs): horizontalalignment="left", verticalalignment="bottom", ) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() @@ -1319,7 +1326,7 @@ def plot_glmnet_cv_results( tick_params, and legend are resized with 0.85, 0.85, 0.75, and 0.85 fraction of title fontsize, respectively. - grid : bool, optional (default=True) + grid: bool, optional (default=True) Whether to show (x,y) grid on the plot. legend: bool, optional (default=True) From fa585afda25df170eff2a09d73e0f192b90b2312 Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:35:49 -0500 Subject: [PATCH 3/8] Update savepath in all plots ... --- slickml/classification.py | 60 +++++++++++++++++++++++----------- slickml/feature_selection.py | 35 +++++++++++++------- slickml/metrics.py | 8 +++-- slickml/plotting.py | 62 ++++++++++++++++++++++++++++++++++-- 4 files changed, 131 insertions(+), 34 deletions(-) diff --git a/slickml/classification.py b/slickml/classification.py index be25dff..801f579 100644 --- a/slickml/classification.py +++ b/slickml/classification.py @@ -311,6 +311,7 @@ def plot_feature_importance( markerfacecolor=None, markeredgewidth=None, fontsize=None, + save_path=None ): """Function to plot XGBoost feature importance. @@ -347,18 +348,23 @@ def plot_feature_importance( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ plot_xgb_feature_importance( - self.feature_importance_, - figsize, - color, - marker, - markersize, - markeredgecolor, - markerfacecolor, - markeredgewidth, - fontsize, + feature_importance=self.feature_importance_, + figsize=figsize, + color=color, + marker=marker, + markersize=markersize, + markeredgecolor=markeredgecolor, + markerfacecolor=markerfacecolor, + markeredgewidth=markeredgewidth, + fontsize=fontsize, + save_path=save_path ) def plot_shap_summary( @@ -377,6 +383,7 @@ def plot_shap_summary( class_names=None, class_inds=None, color_bar_label=None, + save_path=None ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -433,6 +440,10 @@ def plot_shap_summary( color_bar_label: str, optional, (default="Feature Value") Label for color bar + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ # define tree explainer @@ -466,6 +477,7 @@ def plot_shap_summary( class_names=class_names, class_inds=class_inds, color_bar_label=color_bar_label, + save_path=save_path ) def plot_shap_waterfall( @@ -483,6 +495,7 @@ def plot_shap_waterfall( max_display=None, title=None, fontsize=None, + save_path=None ): """Function to plot shap waterfall plot. This function is a helper function to plot the shap waterfall plot @@ -536,6 +549,10 @@ def plot_shap_waterfall( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ # define tree explainer @@ -568,6 +585,7 @@ def plot_shap_waterfall( max_display=max_display, title=title, fontsize=fontsize, + save_path=save_path ) def _dtrain(self, X_train, y_train): @@ -1026,6 +1044,7 @@ def plot_cv_results( train_std_color=None, test_color=None, test_std_color=None, + save_path=None ): """ Function to plot the results of xgboost.cv() process and evolution @@ -1060,18 +1079,23 @@ def plot_cv_results( test_std_color: str, optional, (default="#D0AAF3") Color of the edge color of the testing std bars + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ plot_xgb_cv_results( - self.cv_results_, - figsize, - linestyle, - train_label, - test_label, - train_color, - train_std_color, - test_color, - test_std_color, + cv_results=self.cv_results_, + figsize=figsize, + linestyle=linestyle, + train_label=train_label, + test_label=test_label, + train_color=train_color, + train_std_color=train_std_color, + test_color=test_color, + test_std_color=test_std_color, + save_path=save_path ) def _cv(self): diff --git a/slickml/feature_selection.py b/slickml/feature_selection.py index 398281e..90d84e5 100644 --- a/slickml/feature_selection.py +++ b/slickml/feature_selection.py @@ -572,6 +572,7 @@ def plot_frequency( markerfacecolor=None, markeredgewidth=None, fontsize=None, + save_path=None ): """Function to plot selected features frequency. @@ -614,20 +615,21 @@ def plot_frequency( """ plot_xfs_feature_frequency( - self.feature_frequency_, - figsize, - freq_pct, - color, - marker, - markersize, - markeredgecolor, - markerfacecolor, - markeredgewidth, - fontsize, + freq=self.feature_frequency_, + figsize=figsize, + freq_pct=freq_pct, + color=color, + marker=marker, + markersize=markersize, + markeredgecolor=markeredgecolor, + markerfacecolor=markerfacecolor, + markeredgewidth=markeredgewidth, + fontsize=fontsize, + save_path=save_path ) def plot_cv_results( - self, figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False + self, figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False, save_path=None ): """Function to plot the cross-validation results of XGBoostFeatureSelector. It visualizes the internal @@ -654,13 +656,22 @@ def plot_cv_results( sharey: bool, optional, (default=False) Flag to share "Y" axis for each row of subplots + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" kwargs: dict Plotting object plotting_cv_ """ plot_xfs_cv_results( - figsize, int_color, ext_color, sharex, sharey, **self.plotting_cv_ + figsize=figsize, + int_color=int_color, + ext_color=ext_color, + sharex=sharex, sharey=sharey, + save_path=save_path, + **self.plotting_cv_ ) def get_xgb_params(self): diff --git a/slickml/metrics.py b/slickml/metrics.py index 1e9301c..6fb794c 100644 --- a/slickml/metrics.py +++ b/slickml/metrics.py @@ -900,7 +900,7 @@ def _plotting_dict(self): return plotting_dict - def plot(self, figsize=None): + def plot(self, figsize=None, save_path=None): """ Function to plot binary classification metrics. This function is a helper function based on the plotting_dict @@ -910,6 +910,10 @@ def plot(self, figsize=None): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" """ - plot_regression_metrics(figsize, **self.plotting_dict_) + plot_regression_metrics(figsize=figsize, save_path=save_path, **self.plotting_dict_) diff --git a/slickml/plotting.py b/slickml/plotting.py index a44a192..032aef5 100644 --- a/slickml/plotting.py +++ b/slickml/plotting.py @@ -251,6 +251,7 @@ def plot_xfs_feature_frequency( markerfacecolor=None, markeredgewidth=None, fontsize=None, + save_path=None ): """Function to plot selected features frequency. This function is a helper function based on the features_frequency @@ -289,6 +290,10 @@ def plot_xfs_feature_frequency( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -382,11 +387,15 @@ def plot_xfs_feature_frequency( ax.set_ylabel("Feature", fontsize=fontsize) ax.set_title("Important Features Frequency", fontsize=fontsize) ax.tick_params(axis="both", which="major", labelsize=fontsize) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() def plot_xfs_cv_results( - figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False, **kwargs + figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False, save_path=None, **kwargs ): """Function to plot the cross-validation results ofXGBoostFeatureSelector. It visualizes the internal and external performance during the @@ -411,6 +420,10 @@ def plot_xfs_cv_results( sharey: bool, optional, (default=False) Flag to share "Y" axis for each row of subplots + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" kwargs: dict() Plotting object plotting_cv_ @@ -457,6 +470,10 @@ def plot_xfs_cv_results( ax4.set( title=f"External {kwargs['n_splits']}-Folds CV {kwargs['eval_metric']} - Test" ) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() @@ -470,6 +487,7 @@ def plot_xgb_cv_results( train_std_color=None, test_color=None, test_std_color=None, + save_path=None ): """Function to plot cv results of XGBoostCVClassifier. @@ -502,6 +520,10 @@ def plot_xgb_cv_results( test_std_color: str, optional, (default="#D0AAF3") Color of the edge color of the testing std bars + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -596,6 +618,9 @@ def plot_xgb_cv_results( ax.set_title(f"""{metric} Evolution vs Boosting Rounds""", fontsize=12) ax.tick_params(axis="both", which="major", labelsize=12) ax.legend(loc=0, prop={"size": 12}, framealpha=0.0) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() @@ -610,6 +635,7 @@ def plot_xgb_feature_importance( markerfacecolor=None, markeredgewidth=None, fontsize=None, + save_path=None ): """Function to plot XGBoost feature importance. This function is a helper function based on the feature_importance_ @@ -645,6 +671,10 @@ def plot_xgb_feature_importance( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -746,6 +776,10 @@ def plot_xgb_feature_importance( ax.set_title("Feature Importance", fontsize=fontsize) ax.set(xlim=[None, feature_importance[colx].max() * 1.13]) ax.tick_params(axis="both", which="major", labelsize=fontsize) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() @@ -765,6 +799,7 @@ def plot_shap_summary( class_names=None, class_inds=None, color_bar_label=None, + save_path=None ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -822,6 +857,10 @@ def plot_shap_summary( color_bar_label: str, optional, (default="Feature Value") Label for color bar + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -878,6 +917,10 @@ def plot_shap_summary( class_inds=class_inds, color_bar_label=color_bar_label, ) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() @@ -896,6 +939,7 @@ def plot_shap_waterfall( max_display=None, title=None, fontsize=None, + save_path=None ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -949,6 +993,10 @@ def plot_shap_waterfall( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -1089,11 +1137,14 @@ def plot_shap_waterfall( title=title, ) ax2.set(xlabel="Composition Ratio (%)") + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() -def plot_regression_metrics(figsize=None, **kwargs): +def plot_regression_metrics(figsize=None, save_path=None, **kwargs): """Function to plot regression metrics. This function is a helper function based on the plotting_dict attribute of the RegressionMetrics class. @@ -1102,6 +1153,10 @@ def plot_regression_metrics(figsize=None, **kwargs): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size + + save_path: str, optional (default=None) + The full or relative path to save the plot including the image format. + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -1277,6 +1332,9 @@ def plot_regression_metrics(figsize=None, **kwargs): ax6.tick_params(axis="both", which="major", labelsize=12) ax6.legend(prop={"size": 12}, loc=4, framealpha=0.0) + + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() From 7115c253bc1d8b22fae65dd191d9b99ccf49ca7e Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:36:20 -0500 Subject: [PATCH 4/8] Update metrics ... --- examples/metrics.ipynb | 55 +++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/examples/metrics.ipynb b/examples/metrics.ipynb index 0b4b73e..f5d29bd 100644 --- a/examples/metrics.ipynb +++ b/examples/metrics.ipynb @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -61,7 +61,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [ { @@ -101,7 +101,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { @@ -131,7 +131,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -169,47 +169,47 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", + " }
Accuracy Balanced Accuracy ROC AUC PR AUC Precision Recall Average Precision F-1 Score F-2 Score F-0.50 Score Threat Score TP TN FP FN
\n", " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", - " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", " \n", "
Accuracy Balanced Accuracy ROC AUC PR AUC Precision Recall Average Precision F-1 Score F-2 Score F-0.50 Score Threat Score TP TN FP FN
Threshold = 0.500 | Average =\n", + " Threshold = 0.500 | Average =\n", " Binary0.9680000.9570000.9880000.9920000.9520001.0000000.9910000.9750000.9900000.9610000.95200011864600.9680000.9570000.9880000.9920000.9520001.0000000.9910000.9750000.9900000.9610000.9520001186460
" ], "text/plain": [ - "" + "" ] }, "metadata": {}, @@ -228,7 +228,8 @@ ], "source": [ "example1 = BinaryClassificationMetrics(y_true, y_pred_proba, precision_digits=3)\n", - "example1.plot()" + "example1.plot(figsize=(12, 12),\n", + " save_path=None)" ] }, { From fc56c9a7010c1cc9183e72538f0b2d96f8604fb6 Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:43:06 -0500 Subject: [PATCH 5/8] Update README ... --- README.md | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 082997e..4014a29 100644 --- a/README.md +++ b/README.md @@ -178,24 +178,16 @@ let others know that you are working on it. Whether the contributions consists o levels. The SlickML community goals are to be helpful and effective. ## Citing SlickML -If you use SlickML in academic work, please consider citing -https://doi.org/10.1117/12.2304418 . +If you use SlickML in academic work, please consider citing it. ### Bibtex Entry: ```bib -@inproceedings{tahmassebi2018ideeple, - title={ideeple: Deep learning in a flash}, - author={Tahmassebi, Amirhessam}, - booktitle={Disruptive Technologies in Information Sciences}, - volume={10652}, - pages={106520S}, - year={2018}, - organization={International Society for Optics and Photonics} +@software{slickml2020, + title={SlickML: Slick Machine Learning in Python}, + author={Tahmassebi, Amirhessam and Smith, Trace}, + url={https://github.com/slickml/slick-ml}, + version={0.1.3}, + year={2021}, } ``` -### APA Entry: - -Tahmassebi, A. (2018, May). ideeple: Deep learning in a flash. In Disruptive -Technologies in Information Sciences (Vol. 10652, p. 106520S). International -Society for Optics and Photonics. From 076031ea11be7e467820dd432f6ee773555d003d Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:43:33 -0500 Subject: [PATCH 6/8] Update version ... --- slickml/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slickml/__init__.py b/slickml/__init__.py index b3f4756..ae73625 100644 --- a/slickml/__init__.py +++ b/slickml/__init__.py @@ -1 +1 @@ -__version__ = "0.1.2" +__version__ = "0.1.3" From 70b5b34ae30060535ac6388658d360b76a522945 Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:48:36 -0500 Subject: [PATCH 7/8] Update CHANGELOG ... --- CHANGELOG.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 26b4ab6..16b35f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,12 +3,22 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## Unreleased + + +## Version 0.1.3 - 2021-05-15 + ### Fixed * [#66](https://github.com/slickml/slick-ml/pull/66) fixed bugs in feature selection algorithm. * [#67](https://github.com/slickml/slick-ml/pull/67) fixed bugs in metrics. ### Updated * [#66](https://github.com/slickml/slick-ml/pull/66) updated the order of the functions inside each class. +* [#68](https://github.com/slickml/slick-ml/pull/68) updated `save_path` in plotting functions. +* [#68](https://github.com/slickml/slick-ml/pull/68) updated `bibtex` citations to software. + +### Added +* [#68](https://github.com/slickml/slick-ml/pull/68) added directories for `JOSS` and `NeurIPS` papers. + ## Version 0.1.2 - 2021-04-17 From 4cf63ccddc72fb7ebc6b1aac1802f9b4eec93dab Mon Sep 17 00:00:00 2001 From: Amirhessam Tahmassebi Date: Sat, 15 May 2021 20:52:37 -0500 Subject: [PATCH 8/8] Black ... --- slickml/classification.py | 32 +++++++------- slickml/feature_selection.py | 23 ++++++---- slickml/metrics.py | 18 ++++---- slickml/plotting.py | 84 +++++++++++++++++++----------------- 4 files changed, 86 insertions(+), 71 deletions(-) diff --git a/slickml/classification.py b/slickml/classification.py index 801f579..a0f7339 100644 --- a/slickml/classification.py +++ b/slickml/classification.py @@ -311,7 +311,7 @@ def plot_feature_importance( markerfacecolor=None, markeredgewidth=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot XGBoost feature importance. @@ -348,10 +348,10 @@ def plot_feature_importance( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ plot_xgb_feature_importance( @@ -364,7 +364,7 @@ def plot_feature_importance( markerfacecolor=markerfacecolor, markeredgewidth=markeredgewidth, fontsize=fontsize, - save_path=save_path + save_path=save_path, ) def plot_shap_summary( @@ -383,7 +383,7 @@ def plot_shap_summary( class_names=None, class_inds=None, color_bar_label=None, - save_path=None + save_path=None, ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -440,10 +440,10 @@ def plot_shap_summary( color_bar_label: str, optional, (default="Feature Value") Label for color bar - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ # define tree explainer @@ -477,7 +477,7 @@ def plot_shap_summary( class_names=class_names, class_inds=class_inds, color_bar_label=color_bar_label, - save_path=save_path + save_path=save_path, ) def plot_shap_waterfall( @@ -495,7 +495,7 @@ def plot_shap_waterfall( max_display=None, title=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot shap waterfall plot. This function is a helper function to plot the shap waterfall plot @@ -549,10 +549,10 @@ def plot_shap_waterfall( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ # define tree explainer @@ -585,7 +585,7 @@ def plot_shap_waterfall( max_display=max_display, title=title, fontsize=fontsize, - save_path=save_path + save_path=save_path, ) def _dtrain(self, X_train, y_train): @@ -1044,7 +1044,7 @@ def plot_cv_results( train_std_color=None, test_color=None, test_std_color=None, - save_path=None + save_path=None, ): """ Function to plot the results of xgboost.cv() process and evolution @@ -1079,10 +1079,10 @@ def plot_cv_results( test_std_color: str, optional, (default="#D0AAF3") Color of the edge color of the testing std bars - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ plot_xgb_cv_results( @@ -1095,7 +1095,7 @@ def plot_cv_results( train_std_color=train_std_color, test_color=test_color, test_std_color=test_std_color, - save_path=save_path + save_path=save_path, ) def _cv(self): diff --git a/slickml/feature_selection.py b/slickml/feature_selection.py index 90d84e5..e7c4093 100644 --- a/slickml/feature_selection.py +++ b/slickml/feature_selection.py @@ -572,7 +572,7 @@ def plot_frequency( markerfacecolor=None, markeredgewidth=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot selected features frequency. @@ -625,11 +625,17 @@ def plot_frequency( markerfacecolor=markerfacecolor, markeredgewidth=markeredgewidth, fontsize=fontsize, - save_path=save_path + save_path=save_path, ) def plot_cv_results( - self, figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False, save_path=None + self, + figsize=None, + int_color=None, + ext_color=None, + sharex=False, + sharey=False, + save_path=None, ): """Function to plot the cross-validation results of XGBoostFeatureSelector. It visualizes the internal @@ -656,10 +662,10 @@ def plot_cv_results( sharey: bool, optional, (default=False) Flag to share "Y" axis for each row of subplots - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" kwargs: dict Plotting object plotting_cv_ @@ -668,10 +674,11 @@ def plot_cv_results( plot_xfs_cv_results( figsize=figsize, int_color=int_color, - ext_color=ext_color, - sharex=sharex, sharey=sharey, + ext_color=ext_color, + sharex=sharex, + sharey=sharey, save_path=save_path, - **self.plotting_cv_ + **self.plotting_cv_, ) def get_xgb_params(self): diff --git a/slickml/metrics.py b/slickml/metrics.py index 6fb794c..eb54374 100644 --- a/slickml/metrics.py +++ b/slickml/metrics.py @@ -545,15 +545,15 @@ def plot(self, figsize=None, save_path=None): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ - plot_binary_classification_metrics(figsize=figsize, - save_path=save_path, - **self.plotting_dict_) + plot_binary_classification_metrics( + figsize=figsize, save_path=save_path, **self.plotting_dict_ + ) class RegressionMetrics: @@ -910,10 +910,12 @@ def plot(self, figsize=None, save_path=None): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" """ - plot_regression_metrics(figsize=figsize, save_path=save_path, **self.plotting_dict_) + plot_regression_metrics( + figsize=figsize, save_path=save_path, **self.plotting_dict_ + ) diff --git a/slickml/plotting.py b/slickml/plotting.py index 032aef5..630b36f 100644 --- a/slickml/plotting.py +++ b/slickml/plotting.py @@ -27,10 +27,10 @@ def plot_binary_classification_metrics(figsize=None, save_path=None, **kwargs): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -233,9 +233,9 @@ def plot_binary_classification_metrics(figsize=None, save_path=None, **kwargs): horizontalalignment="left", verticalalignment="bottom", ) - + if save_path: - plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() @@ -251,7 +251,7 @@ def plot_xfs_feature_frequency( markerfacecolor=None, markeredgewidth=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot selected features frequency. This function is a helper function based on the features_frequency @@ -290,10 +290,10 @@ def plot_xfs_feature_frequency( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -387,15 +387,21 @@ def plot_xfs_feature_frequency( ax.set_ylabel("Feature", fontsize=fontsize) ax.set_title("Important Features Frequency", fontsize=fontsize) ax.tick_params(axis="both", which="major", labelsize=fontsize) - + if save_path: plt.savefig(save_path, bbox_inches="tight", dpi=200) - + plt.show() def plot_xfs_cv_results( - figsize=None, int_color=None, ext_color=None, sharex=False, sharey=False, save_path=None, **kwargs + figsize=None, + int_color=None, + ext_color=None, + sharex=False, + sharey=False, + save_path=None, + **kwargs, ): """Function to plot the cross-validation results ofXGBoostFeatureSelector. It visualizes the internal and external performance during the @@ -420,10 +426,10 @@ def plot_xfs_cv_results( sharey: bool, optional, (default=False) Flag to share "Y" axis for each row of subplots - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" kwargs: dict() Plotting object plotting_cv_ @@ -470,10 +476,10 @@ def plot_xfs_cv_results( ax4.set( title=f"External {kwargs['n_splits']}-Folds CV {kwargs['eval_metric']} - Test" ) - + if save_path: plt.savefig(save_path, bbox_inches="tight", dpi=200) - + plt.show() @@ -487,7 +493,7 @@ def plot_xgb_cv_results( train_std_color=None, test_color=None, test_std_color=None, - save_path=None + save_path=None, ): """Function to plot cv results of XGBoostCVClassifier. @@ -520,10 +526,10 @@ def plot_xgb_cv_results( test_std_color: str, optional, (default="#D0AAF3") Color of the edge color of the testing std bars - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -618,9 +624,9 @@ def plot_xgb_cv_results( ax.set_title(f"""{metric} Evolution vs Boosting Rounds""", fontsize=12) ax.tick_params(axis="both", which="major", labelsize=12) ax.legend(loc=0, prop={"size": 12}, framealpha=0.0) - + if save_path: - plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() @@ -635,7 +641,7 @@ def plot_xgb_feature_importance( markerfacecolor=None, markeredgewidth=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot XGBoost feature importance. This function is a helper function based on the feature_importance_ @@ -671,10 +677,10 @@ def plot_xgb_feature_importance( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -776,10 +782,10 @@ def plot_xgb_feature_importance( ax.set_title("Feature Importance", fontsize=fontsize) ax.set(xlim=[None, feature_importance[colx].max() * 1.13]) ax.tick_params(axis="both", which="major", labelsize=fontsize) - + if save_path: - plt.savefig(save_path, bbox_inches="tight", dpi=200) - + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() @@ -799,7 +805,7 @@ def plot_shap_summary( class_names=None, class_inds=None, color_bar_label=None, - save_path=None + save_path=None, ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -857,10 +863,10 @@ def plot_shap_summary( color_bar_label: str, optional, (default="Feature Value") Label for color bar - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -917,10 +923,10 @@ def plot_shap_summary( class_inds=class_inds, color_bar_label=color_bar_label, ) - + if save_path: plt.savefig(save_path, bbox_inches="tight", dpi=200) - + plt.show() @@ -939,7 +945,7 @@ def plot_shap_waterfall( max_display=None, title=None, fontsize=None, - save_path=None + save_path=None, ): """Function to plot shap summary plot. This function is a helper function to plot the shap summary plot @@ -993,10 +999,10 @@ def plot_shap_waterfall( fontsize: int or float, optional, (default=12) Fontsize for xlabel and ylabel, and ticks parameters - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -1137,9 +1143,9 @@ def plot_shap_waterfall( title=title, ) ax2.set(xlabel="Composition Ratio (%)") - + if save_path: - plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show() @@ -1153,10 +1159,10 @@ def plot_regression_metrics(figsize=None, save_path=None, **kwargs): ---------- figsize: tuple, optional, (default=(12, 12)) Figure size - + save_path: str, optional (default=None) The full or relative path to save the plot including the image format. - For example "myplot.png" or "../../myplot.pdf" + For example "myplot.png" or "../../myplot.pdf" Returns None """ @@ -1332,9 +1338,9 @@ def plot_regression_metrics(figsize=None, save_path=None, **kwargs): ax6.tick_params(axis="both", which="major", labelsize=12) ax6.legend(prop={"size": 12}, loc=4, framealpha=0.0) - + if save_path: - plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.savefig(save_path, bbox_inches="tight", dpi=200) plt.show()