Spaces:
Sleeping
Sleeping
Commit ·
71abe0d
1
Parent(s): 0cc9ead
Add the correlation matrix table
Browse files
src/ai_dashboard/table_plugin/correlation_matrix.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Correlation Matrix Table plugin"""
|
| 2 |
+
|
| 3 |
+
from typing import Any
|
| 4 |
+
import logging
|
| 5 |
+
from dash import html, dash_table
|
| 6 |
+
from ..base import BaseTablePlugin
|
| 7 |
+
|
| 8 |
+
logger = logging.getLogger(__name__)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
class CorrelationMatrixTablePlugin(BaseTablePlugin):
|
| 12 |
+
"""Correlation matrix as a table."""
|
| 13 |
+
|
| 14 |
+
name = "Correlation Matrix Table"
|
| 15 |
+
|
| 16 |
+
def controls(self) -> Any:
|
| 17 |
+
"""No controls needed for this table."""
|
| 18 |
+
return html.Div("No controls for this table.")
|
| 19 |
+
|
| 20 |
+
def render(self, **kwargs: Any) -> Any:
|
| 21 |
+
"""Render the correlation matrix table."""
|
| 22 |
+
df_num = self.dataframe.select_dtypes(include=["number"])
|
| 23 |
+
corr = df_num.corr().reset_index().rename(columns={"index": "Feature"})
|
| 24 |
+
|
| 25 |
+
return dash_table.DataTable( # type: ignore
|
| 26 |
+
id="corr-matrix-table",
|
| 27 |
+
columns=[{"name": c, "id": c} for c in corr.columns],
|
| 28 |
+
data=corr.to_dict("records"),
|
| 29 |
+
style_table={"overflowX": "auto"},
|
| 30 |
+
style_cell={
|
| 31 |
+
"textAlign": "center",
|
| 32 |
+
"padding": "6px",
|
| 33 |
+
"border": "1px solid #ccc",
|
| 34 |
+
"fontFamily": "Times New Roman, Times, serif",
|
| 35 |
+
},
|
| 36 |
+
style_header={"backgroundColor": "#f0f0f0", "fontWeight": "bold"},
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
def register_callbacks(self, app: Any) -> Any:
|
| 40 |
+
"""Register any interactive callbacks for the table."""
|
| 41 |
+
return None
|