Skip to content

Commit

Permalink
feat(sdk): add residualScatterChart
Browse files Browse the repository at this point in the history
  • Loading branch information
dvalleri committed Dec 12, 2024
1 parent 2f21592 commit 844dd9b
Show file tree
Hide file tree
Showing 4 changed files with 142 additions and 4 deletions.
5 changes: 3 additions & 2 deletions sdk/radicalbit_platform_sdk/charts/regression/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
]
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Original file line number Diff line number Diff line change
Expand Up @@ -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'
63 changes: 62 additions & 1 deletion sdk/tests/chart/regression.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -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": []
}
Expand Down

0 comments on commit 844dd9b

Please sign in to comment.