Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: edit regression line structure in model quality dto #117

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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