diff --git a/sdk/radicalbit_platform_sdk/charts/regression/__init__.py b/sdk/radicalbit_platform_sdk/charts/regression/__init__.py index e86e9d6c..cd8cc1ad 100644 --- a/sdk/radicalbit_platform_sdk/charts/regression/__init__.py +++ b/sdk/radicalbit_platform_sdk/charts/regression/__init__.py @@ -1,8 +1,9 @@ from .regression_chart import RegressionChart -from .regression_chart_data import RegressionDistributionChartData, RegressionPredictedActualChartData +from .regression_chart_data import RegressionDistributionChartData, RegressionPredictedActualChartData,RegressionResidualScatterChartData __all__ = [ 'RegressionChart', 'RegressionDistributionChartData', - 'RegressionPredictedActualChartData' + 'RegressionPredictedActualChartData', + 'RegressionResidualScatterChartData' ] diff --git a/sdk/radicalbit_platform_sdk/charts/regression/regression_chart.py b/sdk/radicalbit_platform_sdk/charts/regression/regression_chart.py index 3bfe8acd..83f6ae80 100644 --- a/sdk/radicalbit_platform_sdk/charts/regression/regression_chart.py +++ b/sdk/radicalbit_platform_sdk/charts/regression/regression_chart.py @@ -2,7 +2,7 @@ import numpy as np from ..utils import get_formatted_bucket_data, get_chart_header -from .regression_chart_data import RegressionDistributionChartData, RegressionPredictedActualChartData +from .regression_chart_data import RegressionDistributionChartData, RegressionPredictedActualChartData, RegressionResidualScatterChartData class RegressionChart: @@ -209,3 +209,75 @@ def predicted_actual_chart(self, data: RegressionPredictedActualChartData) -> EC print('\033[1m'+'prediction vs ground_truth') return EChartsRawWidget(option=options) + + def residual_scatter_chart(self, data: RegressionResidualScatterChartData) -> EChartsRawWidget: + + options = { + "grid": { + "left": 20, + "right": 0, + "bottom": 50, + "top": 24, + "containLabel": True + }, + "xAxis": { + "type": "value", + "axisLabel": { + "fontSize": 9, + "color": "#9b99a1" + }, + "splitLine": { + "lineStyle": { + "color": "#9f9f9f54" + } + }, + "name": "prediction", + "nameGap": 25, + "nameLocation": "middle", + "axisLine": { + "lineStyle": { + "width": 2, + "type": "dashed" + } + } + }, + "yAxis": { + "type": "value", + "axisLabel": { + "fontSize": 9, + "color": "#9b99a1" + }, + "splitLine": { + "lineStyle": { + "color": "#9f9f9f54" + } + }, + "name": "standardized residuals", + "nameGap": 25, + "nameLocation": "middle", + "scale": False + }, + "tooltip": { + "axisPointer": { + "show": True, + "type": "cross", + "lineStyle": { + "type": "dashed", + "width": 1 + } + } + }, + "series": [ + { + "name": "", + "type": "scatter", + "emphasis": { + "focus": "series" + }, + "color": data.color, + "data": data.scatter_data + } + ] + } + + return EChartsRawWidget(option=options) diff --git a/sdk/radicalbit_platform_sdk/charts/regression/regression_chart_data.py b/sdk/radicalbit_platform_sdk/charts/regression/regression_chart_data.py index 803ace97..8705cd5c 100644 --- a/sdk/radicalbit_platform_sdk/charts/regression/regression_chart_data.py +++ b/sdk/radicalbit_platform_sdk/charts/regression/regression_chart_data.py @@ -14,3 +14,7 @@ class RegressionPredictedActualChartData(BaseModel): coefficient: float intercept: float color: Optional[str] = '#9B99A1' + +class RegressionResidualScatterChartData(BaseModel): + scatter_data: List[List[float]] + color: Optional[str] = '#9B99A1' \ No newline at end of file diff --git a/sdk/tests/chart/regression.ipynb b/sdk/tests/chart/regression.ipynb index 9c284eec..c57fb28a 100644 --- a/sdk/tests/chart/regression.ipynb +++ b/sdk/tests/chart/regression.ipynb @@ -150,9 +150,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f08f32fe-960b-4bd6-9386-317fa41e5148", "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "e8cf9be9c58e41c7b91782e55a394f4a", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "EChartsRawWidget(option={'grid': {'left': 20, 'right': 0, 'bottom': 50, 'top': 24, 'containLabel': True}, 'xAx…" + ] + }, + "execution_count": 1, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from radicalbit_platform_sdk.charts.regression import RegressionResidualScatterChartData, RegressionChart\n", + "\n", + "RegressionChart().residual_scatter_chart(data=RegressionResidualScatterChartData(\n", + " scatter_data=[[21,0.004549179691821337],[12,0.004549179691821337],[18,0.004549179691821337],[18,-2.4932570457458496],[13,1.157382845878601],[7,0.004549179691821337],[9,0.004549179691821337],[17,0.004549179691821337],[4,0.004549179691821337],[26,0.004549179691821337],[17,0.004549179691821337],[18,0.004549179691821337],[11,0.004549179691821337]]\n", + "))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "a99f3ce1-63de-42a6-8450-1abc2c94a0f5", + "metadata": {}, + "outputs": [ + { + "data": { + "application/vnd.jupyter.widget-view+json": { + "model_id": "9c628c9ae260468d9cd9c2849fe248d3", + "version_major": 2, + "version_minor": 0 + }, + "text/plain": [ + "EChartsRawWidget(option={'grid': {'left': 20, 'right': 0, 'bottom': 50, 'top': 24, 'containLabel': True}, 'xAx…" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "from radicalbit_platform_sdk.charts.regression import RegressionResidualScatterChartData, RegressionChart\n", + "\n", + "RegressionChart().residual_scatter_chart(data=RegressionResidualScatterChartData(\n", + " scatter_data=[[21,0.004549179691821337],[12,0.004549179691821337],[18,0.004549179691821337],[18,-2.4932570457458496],[13,1.157382845878601],[7,0.004549179691821337],[9,0.004549179691821337],[17,0.004549179691821337],[4,0.004549179691821337],[26,0.004549179691821337],[17,0.004549179691821337],[18,0.004549179691821337],[11,0.004549179691821337]],\n", + " color=\"#3695d9\"\n", + "))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "1776a548-0bcd-42c8-949a-2badaaece702", + "metadata": {}, "outputs": [], "source": [] }