Skip to content

Commit

Permalink
[MLC-413] replaced mathplot with plotly (#312)
Browse files Browse the repository at this point in the history
* replaced mathplot with plotly
  • Loading branch information
yromanyshyn committed Dec 23, 2021
1 parent ef3150f commit 625ac3d
Show file tree
Hide file tree
Showing 5 changed files with 3,279 additions and 225 deletions.
1 change: 0 additions & 1 deletion deepchecks/checks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
)

from .performance import (

PerformanceReport,
ConfusionMatrixReport,
RocReport,
Expand Down
21 changes: 12 additions & 9 deletions deepchecks/checks/performance/regression_error_distribution.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# ----------------------------------------------------------------------------
#
"""The regression_error_distribution check module."""
import matplotlib.pyplot as plt
import plotly.express as px
import pandas as pd
from scipy.stats import kurtosis
from sklearn.base import BaseEstimator
Expand Down Expand Up @@ -69,15 +69,18 @@ def _regression_error_distribution(self, dataset: Dataset, model: BaseEstimator)
n_smallest_diff.name = n_smallest_diff.name + ' Prediction Difference'
n_smallest = pd.concat([dataset.data.loc[n_smallest_diff.index], n_smallest_diff], axis=1)

def display_hist():
diff = y_test - y_pred
diff.hist(bins=40)
plt.title('Histogram of prediction errors')
plt.xlabel(f'{dataset.label_name} prediction error')
plt.ylabel('Count')
display = [
px.histogram(
x=diff.values,
nbins=40,
title='Histogram of prediction errors',
labels={'x': f'{dataset.label_name} prediction error', 'y': 'Count'},
width=700, height=500
),
'Largest over estimation errors:', n_largest,
'Largest under estimation errors:', n_smallest
]

display = [display_hist, 'Largest over estimation errors:', n_largest,
'Largest under estimation errors:', n_smallest]
return CheckResult(value=kurtosis_value, display=display)

def add_condition_kurtosis_not_less_than(self, min_kurtosis: float = -0.1):
Expand Down
31 changes: 20 additions & 11 deletions deepchecks/checks/performance/regression_systematic_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
# ----------------------------------------------------------------------------
#
"""The RegressionSystematicError check module."""
import matplotlib.pyplot as plt
import plotly.graph_objects as go
from sklearn.base import BaseEstimator
from sklearn.metrics import mean_squared_error

Expand Down Expand Up @@ -51,16 +51,25 @@ def _regression_error_distribution(self, dataset: Dataset, model: BaseEstimator)
diff = y_test - y_pred
diff_mean = diff.mean()

def display_box_plot():
red_square = dict(markerfacecolor='r', marker='s')
_, ax = plt.subplots()
ax.set_title('Box plot of the model prediction error')
ax.boxplot(diff, vert=False, flierprops=red_square)
ax.axvline(x=diff_mean, linestyle='--')
ax.annotate(xy=(diff_mean + 0.01, 1.2), text='mean error')

display = ['Non-zero mean of the error distribution indicated the presents of \
systematic error in model predictions', display_box_plot]
display = [
'Non-zero mean of the error distribution indicated the presents '
'of systematic error in model predictions',
go.Figure()
.add_trace(go.Box(
x=diff.values,
name='Model Prediction Error',
boxpoints='suspectedoutliers',
marker=dict(outliercolor='red'),
hoverinfo='x',
hoveron='points'))
.update_layout(
title_text='Box plot of the model prediction error',
width=800, height=500)
.add_vline(
x=diff_mean + 0.01,
line_dash='dash',
annotation_text='Mean error')
]

return CheckResult(value={'rmse': rmse, 'mean_error': diff_mean}, display=display)

Expand Down

0 comments on commit 625ac3d

Please sign in to comment.