diff --git a/deepchecks/utils/distribution/drift.py b/deepchecks/utils/distribution/drift.py index 8efd22518e..7976e08d59 100644 --- a/deepchecks/utils/distribution/drift.py +++ b/deepchecks/utils/distribution/drift.py @@ -147,9 +147,9 @@ def calc_drift_and_plot(train_column: pd.Series, test_column: pd.Series, plot_ti # Should never reach here raise DeepchecksValueError(f'Unsupported column type for drift: {column_type}') - fig = make_subplots(rows=2, cols=1, vertical_spacing=0.4, shared_yaxes=False, shared_xaxes=False, + fig = make_subplots(rows=2, cols=1, vertical_spacing=0.2, shared_yaxes=False, shared_xaxes=False, row_heights=[0.1, 0.9], - subplot_titles=['Drift Score - ' + scorer_name, plot_title]) + subplot_titles=['Drift Score - ' + scorer_name, 'Distribution Plot']) fig.add_traces(bar_traces, rows=[1] * len(bar_traces), cols=[1] * len(bar_traces)) fig.add_traces(dist_traces, rows=[2] * len(dist_traces), cols=[1] * len(dist_traces)) @@ -164,7 +164,8 @@ def calc_drift_and_plot(train_column: pd.Series, test_column: pd.Series, plot_ti yanchor='top', y=0.6), width=700, - height=400 + height=400, + title=plot_title ) fig.update_layout(shared_layout) diff --git a/deepchecks/utils/distribution/plot.py b/deepchecks/utils/distribution/plot.py index 17e14428be..5c1ffb5068 100644 --- a/deepchecks/utils/distribution/plot.py +++ b/deepchecks/utils/distribution/plot.py @@ -192,7 +192,7 @@ def feature_distribution_traces(train_column, xaxis_layout = dict(fixedrange=False, range=x_range_to_show, - title='Distribution') + title='Value') yaxis_layout = dict(title='Probability Density', fixedrange=True) return traces, xaxis_layout, yaxis_layout diff --git a/deepchecks/vision/checks/distribution/train_test_label_drift.py b/deepchecks/vision/checks/distribution/train_test_label_drift.py index 7b8e60413b..14e53099e6 100644 --- a/deepchecks/vision/checks/distribution/train_test_label_drift.py +++ b/deepchecks/vision/checks/distribution/train_test_label_drift.py @@ -458,9 +458,9 @@ def calc_drift_and_plot(train_distribution: dict, test_distribution: dict, plot_ raise DeepchecksValueError( f'column_type must be one of ["numerical", "categorical"], instead got {column_type}') - fig = make_subplots(rows=2, cols=1, vertical_spacing=0.4, shared_yaxes=False, shared_xaxes=False, + fig = make_subplots(rows=2, cols=1, vertical_spacing=0.2, shared_yaxes=False, shared_xaxes=False, row_heights=[0.1, 0.9], - subplot_titles=['Drift Score - ' + scorer_name, plot_title]) + subplot_titles=['Drift Score - ' + scorer_name, 'Distribution Plot']) fig.add_traces(bar_traces, rows=[1] * len(bar_traces), cols=[1] * len(bar_traces)) fig.add_traces(dist_traces, rows=[2] * len(dist_traces), cols=[1] * len(dist_traces)) @@ -475,7 +475,8 @@ def calc_drift_and_plot(train_distribution: dict, test_distribution: dict, plot_ yanchor='top', y=0.6), width=700, - height=400 + height=400, + title=plot_title ) fig.update_layout(shared_layout) @@ -534,7 +535,7 @@ def feature_distribution_traces(expected_percents: np.array, y_lim = 1 if max_y > 0.5 else max_y * 1.1 xaxis_layout = dict(type='category', - title='Values') + title='Value') yaxis_layout = dict(fixedrange=True, range=(0, y_lim), title='Percentage') @@ -549,7 +550,7 @@ def feature_distribution_traces(expected_percents: np.array, xaxis_layout = dict(fixedrange=True, range=x_range, - title='Distribution') + title='Value') yaxis_layout = dict(title='Probability Density') return traces, xaxis_layout, yaxis_layout diff --git a/docs/source/examples/tabular/checks/distribution/train_test_feature_drift.ipynb b/docs/source/examples/tabular/checks/distribution/train_test_feature_drift.ipynb index 7e5bb29d21..f63b51995d 100644 --- a/docs/source/examples/tabular/checks/distribution/train_test_feature_drift.ipynb +++ b/docs/source/examples/tabular/checks/distribution/train_test_feature_drift.ipynb @@ -72,14 +72,7 @@ "cell_type": "code", "execution_count": 1, "id": "3693b3f5-b3e5-4960-9373-ff5279328aea", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:27.848793Z", - "iopub.status.busy": "2022-02-14T16:54:27.847881Z", - "iopub.status.idle": "2022-02-14T16:54:28.086633Z", - "shell.execute_reply": "2022-02-14T16:54:28.087046Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", @@ -101,14 +94,7 @@ "cell_type": "code", "execution_count": 2, "id": "fa391638-4c7c-48b8-b1ca-a92a029d96e2", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:28.095488Z", - "iopub.status.busy": "2022-02-14T16:54:28.094927Z", - "iopub.status.idle": "2022-02-14T16:54:28.102854Z", - "shell.execute_reply": "2022-02-14T16:54:28.103380Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -216,14 +202,7 @@ "cell_type": "code", "execution_count": 3, "id": "80fccd9b-8281-48ec-9170-8933843c50ea", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:28.108640Z", - "iopub.status.busy": "2022-02-14T16:54:28.108092Z", - "iopub.status.idle": "2022-02-14T16:54:28.110230Z", - "shell.execute_reply": "2022-02-14T16:54:28.110761Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "df_test['numeric_with_drift'] = df_test['numeric_with_drift'].astype('float') + abs(np.random.randn(1000)) + np.arange(0, 1, 0.001) * 4\n", @@ -244,14 +223,7 @@ "cell_type": "code", "execution_count": 4, "id": "e3b2e30a-4fdf-461e-90ba-a57fa313b237", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:28.114458Z", - "iopub.status.busy": "2022-02-14T16:54:28.113951Z", - "iopub.status.idle": "2022-02-14T16:54:29.219060Z", - "shell.execute_reply": "2022-02-14T16:54:29.218507Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "from sklearn.compose import ColumnTransformer\n", @@ -266,14 +238,7 @@ "cell_type": "code", "execution_count": 5, "id": "fc48571d-208e-42c5-b86e-a9166e2df10c", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:29.224583Z", - "iopub.status.busy": "2022-02-14T16:54:29.223934Z", - "iopub.status.idle": "2022-02-14T16:54:29.225532Z", - "shell.execute_reply": "2022-02-14T16:54:29.226035Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "model = Pipeline([\n", @@ -296,14 +261,7 @@ "cell_type": "code", "execution_count": 6, "id": "654f8610-87af-4dc3-b20c-7f02d637a82e", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:29.231762Z", - "iopub.status.busy": "2022-02-14T16:54:29.231155Z", - "iopub.status.idle": "2022-02-14T16:54:29.241062Z", - "shell.execute_reply": "2022-02-14T16:54:29.241482Z" - } - }, + "metadata": {}, "outputs": [], "source": [ "label = np.random.randint(0, 2, size=(df_train.shape[0],))\n", @@ -332,14 +290,7 @@ "cell_type": "code", "execution_count": 7, "id": "a7f6888e-7027-4f50-bf5c-617d9997fe2c", - "metadata": { - "execution": { - "iopub.execute_input": "2022-02-14T16:54:29.245705Z", - "iopub.status.busy": "2022-02-14T16:54:29.245118Z", - "iopub.status.idle": "2022-02-14T16:54:29.795740Z", - "shell.execute_reply": "2022-02-14T16:54:29.785251Z" - } - }, + "metadata": {}, "outputs": [ { "data": { @@ -663,152 +614,152 @@ "y": [ 0.008643564510182207, 0.0097313599036168, - 0.012291114835525434, - 0.023802879825654547, - 0.04617434556472055, - 0.059565294736461286, - 0.07752413435831333, - 0.10616641406486316, + 0.012291114835525429, + 0.02380287982565454, + 0.04617434556472058, + 0.05956529473646129, + 0.07752413435831335, + 0.10616641406486314, 0.11507599727139897, - 0.13387869832746113, - 0.1534413917055736, + 0.1338786983274612, + 0.15344139170557364, 0.1549326095304217, - 0.17829661792680426, - 0.194003123889042, - 0.20202105554567631, - 0.22537718870300008, - 0.2453264531662909, - 0.24724344900520018, - 0.2674648118198182, + 0.17829661792680415, + 0.19400312388904195, + 0.20202105554567626, + 0.22537718870300014, + 0.24532645316629087, + 0.2472434490052002, + 0.26746481181981824, 0.28209777873861897, - 0.29412304997328903, - 0.29941230083601605, + 0.294123049973289, + 0.299412300836016, 0.3095464763489191, - 0.32443290678227066, - 0.3335277217565046, - 0.34039405691542163, - 0.34168528431198636, + 0.3244329067822707, + 0.3335277217565047, + 0.3403940569154216, + 0.3416852843119863, 0.34941705963446384, 0.3547849796870528, 0.3583231713864199, - 0.35939476845706503, + 0.359394768457065, 0.3603562042276419, - 0.3604621383648967, - 0.3622804989089966, - 0.3630874535472984, + 0.36046213836489666, + 0.36228049890899666, + 0.3630874535472983, 0.3636108608395067, 0.3639627398816688, 0.36396827293793077, - 0.3644123770466785, - 0.36448850076134814, - 0.36542218254809605, + 0.36441237704667845, + 0.3644885007613481, + 0.36542218254809616, 0.3672765865505002, - 0.36877984878391473, - 0.3694941531583814, + 0.3687798487839149, + 0.36949415315838147, 0.3705503793865524, 0.37181885948267196, 0.371907712261106, - 0.37179774133782373, + 0.37179774133782384, 0.3702181925231392, - 0.3700335671941468, - 0.36747830288659716, - 0.3674775505187848, + 0.3700335671941469, + 0.3674783028865972, + 0.36747755051878467, 0.3630997580925576, - 0.35831831599080094, + 0.3583183159908009, 0.34921974876639744, - 0.34900387871780175, - 0.3414946773967452, - 0.33658609004098033, - 0.32419468419557607, + 0.3490038787178017, + 0.3414946773967453, + 0.3365860900409804, + 0.3241946841955761, 0.30713047621783895, 0.3069111492908705, - 0.2889187604218177, + 0.28891876042181763, 0.2878608081652905, 0.27067960684868714, 0.2538685334622671, - 0.2517404700430906, - 0.23398818533528418, - 0.23000324949865247, + 0.2517404700430905, + 0.2339881853352842, + 0.23000324949865253, 0.22070696808563284, 0.21333851886251348, - 0.20082009276839294, + 0.20082009276839302, 0.19207235945158094, - 0.18553541416855004, - 0.169779786216548, - 0.16515140174847648, - 0.14599574778227561, + 0.1855354141685502, + 0.16977978621654796, + 0.16515140174847653, + 0.14599574778227564, 0.14412898522359985, - 0.14255744681017873, + 0.14255744681017876, 0.12892974520978115, 0.11555329686844219, - 0.11302460137951365, + 0.11302460137951369, 0.11035784610493403, 0.10178138922764243, 0.09159737093435315, 0.08817866480530666, - 0.07943664879531603, - 0.07853752165619546, + 0.07943664879531606, + 0.07853752165619547, 0.0674406565792129, - 0.057670483055018956, - 0.052309119516128495, - 0.051650467734899244, - 0.050006980402568284, + 0.05767048305501899, + 0.05230911951612851, + 0.05165046773489929, + 0.05000698040256827, 0.0416435731110521, - 0.03372467811099224, - 0.03191830159827876, + 0.03372467811099226, + 0.03191830159827877, 0.025868439137504758, - 0.021538527179602706, - 0.021280458427895013, - 0.017428859009940994, - 0.013651160506040523, - 0.011295800447853364, - 0.010544167384582163, - 0.007817835132377637, - 0.005730833293491814, - 0.005684167296088494, - 0.004913184321687076, + 0.021538527179602692, + 0.021280458427895027, + 0.01742885900994099, + 0.01365116050604052, + 0.011295800447853378, + 0.010544167384582179, + 0.007817835132377635, + 0.005730833293491813, + 0.0056841672960885, + 0.0049131843216870755, 0.00395340158027361, - 0.003448725923613315, - 0.003344332793455088, - 0.0028889400788104243, - 0.002282303087459186, - 0.0020062140631202322, - 0.001805958869112873, - 0.0016592878214707436, - 0.001664122554701852, - 0.001674783855632724, + 0.0034487259236133175, + 0.0033443327934550896, + 0.0028889400788104265, + 0.0022823030874591847, + 0.002006214063120231, + 0.0018059588691128716, + 0.0016592878214707427, + 0.0016641225547018514, + 0.0016747838556327237, 0.0016601032441792493, 0.0015363432295141667, 0.00151360152636744, - 0.0012193646852390288, - 0.0007875981060122955, - 0.000784272948585929, - 0.00026330096248731956, - 0.0001918686269271346, - 8.590966033759907e-05, - 2.1837028820746467e-05, - 1.4075228304934558e-05, - 1.3926325391664822e-06, - 1.159171411492843e-06, - 9.647843634959636e-08, - 2.8694281371005734e-08, - 1.5013032647092797e-09, - 3.312299811861638e-10, - 8.134790895764945e-12, - 1.7829937979563843e-12, - 4.4756473675025805e-15, - 4.379803369045627e-15, - 5.238991816127292e-18, - 2.8597324760808093e-21, - 9.479744053430697e-22, - 7.279288356069833e-25, - 8.640487940915884e-29, - 4.782703324915297e-33, - 1.2345095231000215e-37, - 1.4859400068292412e-42, - 8.340535506630727e-48, - 2.183093940632519e-53, - 2.664628947904535e-59 + 0.001219364685239029, + 0.0007875981060122975, + 0.0007842729485859275, + 0.00026330096248731874, + 0.00019186862692713395, + 8.59096603375987e-05, + 2.1837028820746585e-05, + 1.4075228304934636e-05, + 1.3926325391664727e-06, + 1.1591714114928353e-06, + 9.647843634959707e-08, + 2.8694281371005995e-08, + 1.5013032647092666e-09, + 3.312299811861603e-10, + 8.134790895765032e-12, + 1.7829937979564035e-12, + 4.475647367502534e-15, + 4.379803369045579e-15, + 5.2389918161273664e-18, + 2.8597324760807687e-21, + 9.479744053430833e-22, + 7.2792883560697305e-25, + 8.6404879409157e-29, + 4.78270332491523e-33, + 1.2345095231000043e-37, + 1.4859400068292205e-42, + 8.340535506630492e-48, + 2.183093940632488e-53, + 2.6646289479045355e-59 ], "yaxis": "y2" }, @@ -1134,7 +1085,7 @@ "x": 0.5, "xanchor": "center", "xref": "paper", - "y": 1.0, + "y": 1.0000000000000002, "yanchor": "bottom", "yref": "paper" }, @@ -1143,11 +1094,11 @@ "size": 16 }, "showarrow": false, - "text": "numeric_with_drift (#1 in FI)", + "text": "Distribution Plot", "x": 0.5, "xanchor": "center", "xref": "paper", - "y": 0.54, + "y": 0.7200000000000001, "yanchor": "bottom", "yref": "paper" } @@ -1157,6 +1108,7 @@ "title": { "text": "Dataset" }, + "x": 1.02, "y": 0.6, "yanchor": "top" }, @@ -1236,7 +1188,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1272,7 +1224,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1296,7 +1248,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1332,7 +1284,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1347,7 +1299,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1383,7 +1335,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1410,7 +1362,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1446,7 +1398,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1461,7 +1413,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1497,7 +1449,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1643,7 +1595,7 @@ }, "colorscale": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1679,7 +1631,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], @@ -1770,7 +1722,7 @@ ], "sequential": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1806,13 +1758,13 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ], "sequentialminus": [ [ - 0.0, + 0, "#0d0887" ], [ @@ -1848,7 +1800,7 @@ "#fdca26" ], [ - 1.0, + 1, "#f0f921" ] ] @@ -1977,12 +1929,15 @@ } } }, + "title": { + "text": "numeric_with_drift (#1 in FI)" + }, "width": 700, "xaxis": { "anchor": "y", "domain": [ - 0.0, - 1.0 + 0, + 1 ], "dtick": 0.05, "fixedrange": true, @@ -1992,13 +1947,14 @@ 0, 0.4 ], - "showgrid": false + "showgrid": false, + "type": "linear" }, "xaxis2": { "anchor": "y2", "domain": [ - 0.0, - 1.0 + 0, + 1 ], "fixedrange": false, "range": [ @@ -2006,39 +1962,52 @@ 6.176979021411623 ], "title": { - "text": "Distribution" - } + "text": "Value" + }, + "type": "linear" }, "yaxis": { "anchor": "x", + "autorange": true, "color": "black", "domain": [ - 0.9400000000000001, - 1.0 + 0.9200000000000002, + 1 ], "fixedrange": true, + "range": [ + -0.5, + 0.5 + ], "showgrid": false, "showline": false, "showticklabels": false, + "type": "category", "zeroline": false }, "yaxis2": { "anchor": "x2", + "autorange": true, "domain": [ - 0.0, - 0.54 + 0, + 0.7200000000000001 ], "fixedrange": true, + "range": [ + 0, + 0.3914818023801116 + ], "title": { "text": "Probability Density" - } + }, + "type": "linear" } } }, "text/html": [ - "