Skip to content

Commit

Permalink
Dev/sklearn (#119)
Browse files Browse the repository at this point in the history
* Links, docstrings and error fixes

* Added logging regression to sklearn integration

* Added all list

* Small fixes

* Refactor, added more visuals

* refactor

* Added classifier summary

* Dropped try catch clauses

* Added visuals to classifier

* Changed visuals

* Minor fixes

* Added clustering

* Updated dependencies

* moved private method down

* k matches kmeans api

* Added log csv to api

* Log csv, not html, fix in getting pred proba

* Added docstring, changed interface

* fix

* Refactor - log meta-data separately

* Refactor - log meta-data separately, added docstrings

* docs fixes

* disable module too long

* fix

* added model name option

* print exception msg

* added explicit parameter html or csv, made str formatting consistent

* docstring fix

* added number of rows option for logging csv

* fix

* Changed log_test_score to log_scores
  • Loading branch information
Kamil A. Kaczmarek authored Dec 15, 2020
1 parent 839ad07 commit fc89713
Show file tree
Hide file tree
Showing 11 changed files with 1,295 additions and 37 deletions.
3 changes: 2 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
'optuna',
'scikitplot',
'scikitplot.metrics',
'xgboost']
'xgboost',
'yellowbrick']

# -- Project information -----------------------------------------------------

Expand Down
3 changes: 2 additions & 1 deletion docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ And the best thing is you can extend it yourself or... tell us to do it for you
api.chart <user_guide/api/chart>
api.explainers <user_guide/api/explainers>
api.html <user_guide/api/html>
api.table <user_guide/api/table>
api.table <user_guide/api/table>
api.utils <user_guide/api/utils>
api.video <user_guide/api/video>
hpo.utils <user_guide/hpo/utils>
bots.telegram_bot <user_guide/bots/telegram_bot>
monitoring.keras <user_guide/monitoring/keras>
monitoring.lightgbm <user_guide/monitoring/lightgbm>
monitoring.xgboost <user_guide/monitoring/xgboost>
monitoring.sklearn <user_guide/monitoring/sklearn>
monitoring.fastai <user_guide/monitoring/fastai>
monitoring.metrics <user_guide/monitoring/metrics>
monitoring.fairness <user_guide/monitoring/fairness>
Expand Down
6 changes: 6 additions & 0 deletions docs/user_guide/monitoring/sklearn.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Scikit-learn
============

.. automodule:: neptunecontrib.monitoring.sklearn
:members:
:show-inheritance:
3 changes: 2 additions & 1 deletion neptunecontrib/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from neptunecontrib.api.chart import log_chart
from neptunecontrib.api.explainers import log_explainer, log_local_explanations, log_global_explanations
from neptunecontrib.api.html import log_html
from neptunecontrib.api.table import log_table
from neptunecontrib.api.table import log_table, log_csv
from neptunecontrib.api.utils import (
concat_experiments_on_channel,
extract_project_progress_info,
Expand All @@ -39,6 +39,7 @@
'log_audio',
'log_video',
'log_table',
'log_csv',
'log_html',
'log_chart',
'log_pickle',
Expand Down
5 changes: 2 additions & 3 deletions neptunecontrib/api/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@ def log_html(name, html, experiment=None):
Args:
name (:obj:`str`):
| Name of the chart (without extension) that will be used as a part of artifact's destination.
html_body (:obj:`str`):
html (:obj:`str`):
| HTML string that is logged and rendered as HTML.
experiment (:obj:`neptune.experiments.Experiment`, optional, default is ``None``):
| For advanced users only. Pass Neptune
`Experiment <https://docs.neptune.ai/neptune-client/docs/experiment.html#neptune.experiments.Experiment>`_
| For advanced users only. Pass Neptune ``Experiment``
object if you want to control to which experiment data is logged.
| If ``None``, log to currently active, and most recent experiment.
Expand Down
49 changes: 45 additions & 4 deletions neptunecontrib/api/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#

import neptune

__all__ = [
'log_table',
'log_csv',
]


def log_table(name, table, experiment=None):
"""Logs pandas dataframe to neptune.
Expand Down Expand Up @@ -62,13 +63,53 @@ def log_table(name, table, experiment=None):
"""
_exp = experiment if experiment else neptune

_exp.log_artifact(export_pandas_dataframe(table), "tables/" + name + '.html')
_exp.log_artifact(export_pandas_dataframe(table, 'html'), 'tables/{}.html'.format(name))


def log_csv(name, table, experiment=None):
"""Logs pandas dataframe to neptune as csv file.
Pandas dataframe is converted to csv fie and logged to Neptune as an artifact with path csv/{name}.csv
Args:
name (:obj:`str`):
| Name of the file (without extension) that will be used as a part of csv's destination.
table (:obj:`pandas.Dataframe`):
| DataFrame table
experiment (:obj:`neptune.experiments.Experiment`, optional, default is ``None``):
| Neptune Experiment object if you want to control to which experiment you log the data.
| If ``None``, log to currently active, and most recent experiment.
Examples:
Create or load dataframe:
def export_pandas_dataframe(table):
.. code:: python3
import pandas as pd
iris_df = pd.read_csv('https://raw.githubusercontent.com/mwaskom/seaborn-data/master/iris.csv', nrows=100)
Log it to Neptune:
.. code:: python3
from neptunecontrib.api import log_csv
log_csv('pandas_df', iris_df)
"""
_exp = experiment if experiment else neptune

_exp.log_artifact(export_pandas_dataframe(table, 'csv'), 'csv/{}.csv'.format(name))


def export_pandas_dataframe(table, target_type):
from io import StringIO

buffer = StringIO(table.to_html())
if target_type == 'csv':
buffer = StringIO(table.to_csv())
elif target_type == 'html':
buffer = StringIO(table.to_html())
else:
ValueError('Unsupported format: {}'.format(target_type))

buffer.seek(0)

return buffer
Loading

0 comments on commit fc89713

Please sign in to comment.