Skip to content

Commit

Permalink
fix: edit regression line structure in model quality dto, edit demo m…
Browse files Browse the repository at this point in the history
…odel
  • Loading branch information
dtria91 committed Jul 17, 2024
1 parent d5d862d commit 19a3a28
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
7 changes: 6 additions & 1 deletion api/app/models/metrics/model_quality_dto.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,19 @@ class Histogram(BaseModel):
values: Optional[List[int]] = None


class RegressionLine(BaseModel):
coefficient: Optional[float] = None
intercept: Optional[float] = None


class ResidualsMetrics(BaseModel):
ks: KsMetrics
correlation_coefficient: Optional[float] = None
histogram: Histogram
standardized_residuals: List[float]
predictions: List[float]
targets: List[float]
regression_line: List[List[float]]
regression_line: RegressionLine

model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)

Expand Down
5 changes: 4 additions & 1 deletion api/tests/commons/db_mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ def get_sample_current_dataset(
'standardized_residuals': [0.02, 0.03],
'targets': [1, 2.2, 3],
'predictions': [1.3, 2, 4.5],
'regression_line': [[1.2, 0.3], [1.4, 2.3]],
'regression_line': {
'coefficient': 0.7942363125434776,
'intercept': 2.8227418911402906,
},
},
}

Expand Down
4 changes: 2 additions & 2 deletions init-data/init_db.sql

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion sdk/radicalbit_platform_sdk/models/dataset_model_quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,19 @@ class Histogram(BaseModel):
values: Optional[List[int]] = None


class RegressionLine(BaseModel):
coefficient: Optional[float] = None
intercept: Optional[float] = None


class ResidualsMetrics(BaseModel):
ks: KsMetrics
correlation_coefficient: Optional[float] = None
histogram: Histogram
standardized_residuals: List[float]
predictions: List[float]
targets: List[float]
regression_line: List[List[float]]
regression_line: RegressionLine

model_config = ConfigDict(populate_by_name=True, alias_generator=to_camel)

Expand Down
15 changes: 14 additions & 1 deletion sdk/tests/apis/model_current_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,8 @@ def test_regression_model_quality_ok(self):
p_value = 0.2
statistic = 0.4
correlation_coefficient = 0.2
regression_line_coefficient = 0.7957916804773302
regression_line_intercept = 2.7608502737828453
model_current_dataset = ModelCurrentDataset(
base_url,
model_id,
Expand Down Expand Up @@ -1003,7 +1005,10 @@ def test_regression_model_quality_ok(self):
"standardizedResiduals": [0.02, 0.03],
"targets": [1, 2.2, 3],
"predictions": [1.3, 2, 4.5],
"regression_line": [[1.2, 0.3], [1.4, 2.3]]
"regression_line": {{
"coefficient": {regression_line_coefficient},
"intercept": {regression_line_intercept}
}}
}}
}},
"grouped_metrics": {{
Expand Down Expand Up @@ -1056,6 +1061,14 @@ def test_regression_model_quality_ok(self):
)
assert metrics.global_metrics.residuals.ks.p_value == p_value
assert metrics.global_metrics.residuals.ks.statistic == statistic
assert (
metrics.global_metrics.residuals.regression_line.coefficient
== regression_line_coefficient
)
assert (
metrics.global_metrics.residuals.regression_line.intercept
== regression_line_intercept
)
assert metrics.grouped_metrics.r2[0].value == r2
assert metrics.grouped_metrics.mae[0].value == mae
assert metrics.grouped_metrics.mse[0].value == mse
Expand Down
11 changes: 10 additions & 1 deletion sdk/tests/apis/model_reference_dataset_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,8 @@ def test_regression_model_metrics_ok(self):
p_value = 0.2
statistic = 0.4
correlation_coefficient = 0.2
regression_line_coefficient = 0.7942363125434776
regression_line_intercept = 2.8227418911402906
model_reference_dataset = ModelReferenceDataset(
base_url,
model_id,
Expand Down Expand Up @@ -392,7 +394,10 @@ def test_regression_model_metrics_ok(self):
"standardizedResiduals": [0.02, 0.03],
"targets": [1, 2.2, 3],
"predictions": [1.3, 2, 4.5],
"regression_line": [[1.2, 0.3], [1.4, 2.3]]
"regression_line": {{
"coefficient": {regression_line_coefficient},
"intercept": {regression_line_intercept}
}}
}}
}}
}}""",
Expand All @@ -411,6 +416,10 @@ def test_regression_model_metrics_ok(self):
assert metrics.residuals.correlation_coefficient == correlation_coefficient
assert metrics.residuals.ks.p_value == p_value
assert metrics.residuals.ks.statistic == statistic
assert (
metrics.residuals.regression_line.coefficient == regression_line_coefficient
)
assert metrics.residuals.regression_line.intercept == regression_line_intercept
assert model_reference_dataset.status() == JobStatus.SUCCEEDED

@responses.activate
Expand Down

0 comments on commit 19a3a28

Please sign in to comment.