diff --git a/README.md b/README.md index 3497ea3..9f2b322 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ counterpart. ```python from linear_regression import linear_regression + df = pd.DataFrame({"temperature":[...], "signal":[...]}) regression = linear_regression(df, x="temperature", y="signal") diff --git a/linear_regression.py b/linear_regression.py index 7eb2e86..356af39 100644 --- a/linear_regression.py +++ b/linear_regression.py @@ -1,11 +1,11 @@ +import dataclasses import pandas as pd import pytest -from dataclasses import dataclass from sklearn import linear_model -@dataclass +@dataclasses.dataclass class Regression: intercept: float coefficient: float @@ -28,6 +28,9 @@ class Regression: msg = "predict() expects 1 argument, got 0" raise TypeError(msg) + def to_dict(self): + return dataclasses.asdict(self) + def linear_regression(data: pd.DataFrame, *, x: str, y: str) -> Regression: """calculates a linear regression for two columns of a DataFrame"""