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 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. 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)" ] }, { 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 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" diff --git a/slickml/classification.py b/slickml/classification.py index be25dff..a0f7339 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..e7c4093 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,27 @@ 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 @@ -655,12 +663,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 9a62fb8..eb54374 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: @@ -894,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 @@ -904,6 +910,12 @@ 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 04c38ac..630b36f 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 @@ -28,6 +28,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 """ @@ -230,6 +234,9 @@ def plot_binary_classification_metrics(figsize=None, **kwargs): verticalalignment="bottom", ) + if save_path: + plt.savefig(save_path, bbox_inches="tight", dpi=200) + plt.show() @@ -244,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 @@ -283,6 +291,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 """ @@ -375,11 +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, **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 @@ -405,6 +427,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_ @@ -450,6 +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() @@ -463,6 +493,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. @@ -496,6 +527,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 """ @@ -590,6 +625,9 @@ def plot_xgb_cv_results( 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() @@ -603,6 +641,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_ @@ -639,6 +678,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 """ @@ -739,6 +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.show() @@ -758,6 +805,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 @@ -816,6 +864,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 """ @@ -871,6 +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() @@ -889,6 +945,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 @@ -943,6 +1000,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 """ @@ -1083,10 +1144,13 @@ def plot_shap_waterfall( ) 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. @@ -1096,6 +1160,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 """ @@ -1271,6 +1339,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() @@ -1319,7 +1390,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)