Skip to content

Commit

Permalink
removing telemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
edublancas committed Sep 18, 2024
1 parent 96456ee commit 175e6c9
Show file tree
Hide file tree
Showing 15 changed files with 0 additions and 406 deletions.
50 changes: 0 additions & 50 deletions doc/reference/developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -403,53 +403,3 @@ See the [`roc`](https://github.com/ploomber/sklearn-evaluation/blob/8056bc31ec5e
The `ax` object must be returned at the end of the function.

See the [`roc`](https://github.com/ploomber/sklearn-evaluation/blob/8056bc31ec5e372102d0ee5ada988e380b077c4b/src/sklearn_evaluation/plot/roc.py#L45) function for an example.

## Telemetry

Monitoring the state of `sklearn-evaluation`

Use [`SKLearnEvaluationLogger`](https://github.com/ploomber/sklearn-evaluation/blob/f32c15a43f4a9b4c2e588b3c0f71ba6dc5a71a7e/src/sklearn_evaluation/telemetry.py#L19) decorator to generate logs

Example:

```python
@SKLearnEvaluationLogger.log(feature='plot')
def confusion_matrix(
y_true,
y_pred,
target_names=None,
normalize=False,
cmap=None,
ax=None,
**kwargs):
pass
```

this will generate the following log:

```json
{
"metadata": {
"action": "confusion_matrix"
"feature": "plot",
"args": {
"target_names": "None",
"normalize": "False",
"cmap": "None",
"ax": "None"
}
}
}
```

\*\* since `y_true` and `y_pred` are positional arguments without default values it won't log them

### Queries

1. Run queries and filter out `sklearn-evaluation` events by the event name: `sklearn-evaluation`
2. Break these events by feature ('plot', 'report', 'SQLiteTracker', 'NotebookCollection')
3. Break events by actions/func name (i.e: 'confusion_matrix', 'roc', etc...)

### Errors

Failing runnings will be named: `sklearn-evaluation-error`
3 changes: 0 additions & 3 deletions src/sklearn_evaluation/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sklearn_evaluation.nb.NotebookCollection import NotebookCollection
from sklearn_evaluation.nb.NotebookDatabase import NotebookDatabase
from sklearn_evaluation.tracker import SQLiteTracker
from sklearn_evaluation.telemetry import telemetry

__all__ = [
"ClassifierEvaluator",
Expand All @@ -14,5 +13,3 @@
"NotebookCollection",
"NotebookDatabase",
]

telemetry.log_api("imported")
2 changes: 0 additions & 2 deletions src/sklearn_evaluation/evaluator.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sklearn_evaluation.report.report import Report
from sklearn_evaluation.util import estimator_type, class_name
from sklearn_evaluation import plot
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger


class ClassifierEvaluator(object):
Expand Down Expand Up @@ -153,7 +152,6 @@ def html_serializable(self):
"""
return EvaluatorHTMLSerializer(self)

@SKLearnEvaluationLogger.log(feature="report")
def make_report(self, template=None):
"""
Make HTML report
Expand Down
8 changes: 0 additions & 8 deletions src/sklearn_evaluation/grid/random_forest_classifier_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from sklearn_evaluation.grid.classifier_grid import AbstractClassifierGrid, GridTypes
from sklearn.utils.validation import check_consistent_length
import warnings
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger


class RandomForestClassifierGrid(AbstractClassifierGrid):
Expand Down Expand Up @@ -49,7 +48,6 @@ class RandomForestClassifierGrid(AbstractClassifierGrid):
}
)

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-init")
def __init__(self, grid, cv=3, verbose=0):
"""
A random forest classifier grid.
Expand Down Expand Up @@ -96,7 +94,6 @@ def __init__(self, grid, cv=3, verbose=0):
verbose=verbose,
)

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-fit")
def fit(self, X, y):
"""
Fit estimator.
Expand All @@ -121,7 +118,6 @@ def fit(self, X, y):
self.grid_search_cv_.fit(X, y, sample_weight=None)
return self

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-set-test-data")
def set_test_data(self, X_test, y_test) -> None:
"""
Set the test data
Expand All @@ -140,7 +136,6 @@ def set_test_data(self, X_test, y_test) -> None:
self.X_test = X_test
self.y_test = y_test

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-confusion-matrix")
def confusion_matrix(self):
"""
Plots a confusion matrix based on `GridSearchCV.best_estimator_`.
Expand All @@ -160,7 +155,6 @@ def confusion_matrix(self):
y_pred = self.grid_search_cv_.best_estimator_.predict(X_test)
return plot.confusion_matrix(y_test, y_pred)

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-roc")
def roc(self):
"""
Plots an ROC based on `GridSearchCV.best_estimator_`.
Expand All @@ -185,7 +179,6 @@ def roc(self):

return plot.roc(y_test, y_pred)

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-feature-importances")
def feature_importances(self):
"""
Plots feature importances based on `GridSearchCV.best_estimator_`.
Expand All @@ -203,7 +196,6 @@ def feature_importances(self):
feature_importances = self.grid_search_cv_.best_estimator_.feature_importances_
return plot.feature_importances(feature_importances)

@SKLearnEvaluationLogger.log("RandomForestClassifierGrid-grid-search-results")
def grid_search_results(self, change="n_estimators", kind="line"):
"""
Plots grid search results based on `GridSearchCV.best_estimator_`.
Expand Down
4 changes: 0 additions & 4 deletions src/sklearn_evaluation/nb/NotebookCollection.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
from sklearn_evaluation.nb.NotebookIntrospector import NotebookIntrospector
from sklearn_evaluation.nb.sets import differences
from sklearn_evaluation.table import Table
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger

_env = Environment(loader=PackageLoader("sklearn_evaluation", "assets/nb"))
_fm = black.FileMode(string_normalization=False, line_length=40)
Expand All @@ -41,9 +40,6 @@ class NotebookCollection(Mapping):
as identifier (ignores extension)
""" # noqa

@SKLearnEvaluationLogger.log(
feature="NotebookCollection", action="init-NotebookCollection"
)
def __init__(self, paths, ids=None, scores=False):
if ids is None:
ids = paths
Expand Down
4 changes: 0 additions & 4 deletions src/sklearn_evaluation/plot/calibration.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
from sklearn_evaluation import __version__
from sklearn_evaluation.util import isiterofiter
from ploomber_core.exceptions import modify_exceptions
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
from sklearn_evaluation.plot.plot import AbstractComposedPlot, AbstractPlot
from sklearn_evaluation.plot.style import apply_theme, get_color_palette

Expand Down Expand Up @@ -147,7 +146,6 @@ class CalibrationCurve(AbstractPlot):
"""

@modify_exceptions
@SKLearnEvaluationLogger.log(feature="plot", action="calibration-curve-init")
def __init__(
self,
mean_predicted_value,
Expand Down Expand Up @@ -304,7 +302,6 @@ def _get_data(self):

class CalibrationCurveAdd(AbstractComposedPlot):
@modify_exceptions
@SKLearnEvaluationLogger.log(feature="plot", action="calibration-curve-add-init")
def __init__(
self,
mean_predicted_value_list,
Expand Down Expand Up @@ -360,7 +357,6 @@ def plot(self, ax=None):


@modify_exceptions
@SKLearnEvaluationLogger.log(feature="plot")
def calibration_curve(
y_true, probabilities, clf_names=None, n_bins=10, cmap="nipy_spectral", ax=None
):
Expand Down
7 changes: 0 additions & 7 deletions src/sklearn_evaluation/plot/classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from sklearn.metrics import confusion_matrix as sk_confusion_matrix

from sklearn_evaluation import __version__
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
from sklearn_evaluation.plot.matplotlib import bar
from sklearn_evaluation.metrics import precision_at
from sklearn_evaluation import compute
Expand Down Expand Up @@ -93,7 +92,6 @@ class ConfusionMatrix(AbstractPlot):
Added ``cmap`` argument
"""

@SKLearnEvaluationLogger.log(feature="plot", action="confusion-matrix-init")
@modify_exceptions
def __init__(self, cm, *, target_names=None, normalize=False, cmap=None):
self.cm = cm
Expand All @@ -112,14 +110,12 @@ def plot(self, ax=None):

return self

@SKLearnEvaluationLogger.log(feature="plot", action="confusion-matrix-sub")
def __sub__(self, other):
cm = self.cm - other.cm
obj = ConfusionMatrixSub(cm, self.target_names)
obj.plot()
return obj

@SKLearnEvaluationLogger.log(feature="plot", action="confusion-matrix-add")
def __add__(self, other):
obj = ConfusionMatrixAdd(self.cm, other.cm, self.target_names)
obj.plot()
Expand Down Expand Up @@ -178,7 +174,6 @@ def _confusion_matrix(y_true, y_pred, normalize):
return cm


@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def confusion_matrix(
y_true, y_pred, target_names=None, normalize=False, cmap=None, ax=None
Expand Down Expand Up @@ -314,7 +309,6 @@ def _plot_cm(cm, cmap, ax, target_names, normalize):


# http://scikit-learn.org/stable/auto_examples/ensemble/plot_forest_importances.html
@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def feature_importances(
data, top_n=None, feature_names=None, orientation="horizontal", ax=None
Expand Down Expand Up @@ -371,7 +365,6 @@ def feature_importances(
return ax


@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def precision_at_proportions(y_true, y_score, ax=None):
"""
Expand Down
4 changes: 0 additions & 4 deletions src/sklearn_evaluation/plot/classification_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import numpy as np
import matplotlib.pyplot as plt
from sklearn.metrics import classification_report as sk_classification_report
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger

from sklearn_evaluation.plot.classification import _add_values_to_matrix
from sklearn_evaluation.plot.plot import AbstractPlot, AbstractComposedPlot
Expand Down Expand Up @@ -85,7 +84,6 @@ class ClassificationReport(AbstractPlot):
"""

@SKLearnEvaluationLogger.log(feature="plot", action="classification-report-init")
def __init__(
self,
matrix,
Expand All @@ -109,13 +107,11 @@ def plot(self, ax=None):

return self

@SKLearnEvaluationLogger.log(feature="plot", action="classification-report-sub")
def __sub__(self, other):
return ClassificationReportSub(
self.matrix, other.matrix, self.keys, target_names=self.target_names
).plot()

@SKLearnEvaluationLogger.log(feature="plot", action="classification-report-add")
def __add__(self, other):
return ClassificationReportAdd(
self.matrix, other.matrix, keys=self.keys, target_names=self.target_names
Expand Down
7 changes: 0 additions & 7 deletions src/sklearn_evaluation/plot/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@
from sklearn.preprocessing import LabelEncoder
from joblib import Parallel, delayed

from sklearn_evaluation.telemetry import SKLearnEvaluationLogger

from ploomber_core.exceptions import modify_exceptions
from sklearn_evaluation.plot.style import apply_theme

Expand All @@ -61,7 +59,6 @@ def _generate_axes(cluster, figsize, ax):
return ax


@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def elbow_curve(
X,
Expand Down Expand Up @@ -140,7 +137,6 @@ def elbow_curve(


@apply_theme()
@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def elbow_curve_from_results(n_clusters, sum_of_squares, times, ax=None):
"""
Expand Down Expand Up @@ -198,7 +194,6 @@ def _clone_and_score_clusterer(clf, X, n_clusters):
return clf.fit(X).score(X), time.time() - start


@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def silhouette_analysis(
X,
Expand Down Expand Up @@ -298,7 +293,6 @@ def silhouette_analysis(


@apply_theme(cmap_style="gradient")
@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def _silhouette_analysis_one_model(
X,
Expand Down Expand Up @@ -386,7 +380,6 @@ def _silhouette_analysis_one_model(
return ax


@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def silhouette_analysis_from_results(
X,
Expand Down
4 changes: 0 additions & 4 deletions src/sklearn_evaluation/plot/confusion_matrix_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from sklearn.metrics import confusion_matrix as sk_confusion_matrix

from sklearn_evaluation import __version__
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
from sklearn_evaluation.plot.plot import AbstractPlot
from ploomber_core.dependencies import requires
from ploomber_core.exceptions import modify_exceptions
Expand Down Expand Up @@ -264,9 +263,6 @@ class InteractiveConfusionMatrix(AbstractPlot):
.. versionadded:: 0.11.3
"""

@SKLearnEvaluationLogger.log(
feature="plot", action="interactive-confusion-matrix-init"
)
@modify_exceptions
def __init__(self, cm, *, target_names=None, interactive_data=None):
self.cm = cm
Expand Down
3 changes: 0 additions & 3 deletions src/sklearn_evaluation/plot/cumulative_gain_lift_curve.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@

import numpy as np
import matplotlib.pyplot as plt
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
from ploomber_core.exceptions import modify_exceptions
from sklearn_evaluation.plot.style import apply_theme

Expand Down Expand Up @@ -94,7 +93,6 @@ def _cumulative_gain_curve(y_true, y_score, pos_label=None):


@apply_theme()
@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def cumulative_gain(
y_true,
Expand Down Expand Up @@ -178,7 +176,6 @@ def cumulative_gain(


@apply_theme()
@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def lift_curve(
y_true,
Expand Down
3 changes: 0 additions & 3 deletions src/sklearn_evaluation/plot/feature_ranking.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
from scipy.stats import shapiro
from scipy.stats import spearmanr
from scipy.stats import kendalltau as sp_kendalltau
from sklearn_evaluation.telemetry import SKLearnEvaluationLogger
from ploomber_core.exceptions import modify_exceptions

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -153,7 +152,6 @@ def _derive_features_from_ranks(self, ranks):
)
self.features_ = np.array(self.features)

@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def feature_ranks(self, X):
"""
Expand All @@ -174,7 +172,6 @@ def feature_ranks(self, X):

return self.ax

@SKLearnEvaluationLogger.log(feature="plot")
@modify_exceptions
def feature_ranks_custom_algorithm(self, ranks):
"""
Expand Down
Loading

0 comments on commit 175e6c9

Please sign in to comment.