Skip to content

Commit

Permalink
add lowess example
Browse files Browse the repository at this point in the history
  • Loading branch information
david26694 committed Jul 13, 2024
1 parent 53e3489 commit a8c439a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 19 additions & 0 deletions sklego/linear_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,25 @@ class LowessRegression(BaseEstimator, RegressorMixin):
The training data.
y_ : np.ndarray of shape (n_samples,)
The target (training) values.
Example
-------
```python
from sklego.linear_model import LowessRegression
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split
X, y = make_regression(n_samples=100, n_features=2, noise=10)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
lowess = LowessRegression(sigma=1, span=0.5)
lowess.fit(X_train, y_train)
y_pred = lowess.predict(X_test)
print(y_pred)
```
"""

def __init__(self, sigma=1, span=None):
Expand Down
3 changes: 1 addition & 2 deletions tests/test_meta/test_zero_inflated_regressor.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ def test_score_samples():
# Where the classifier prediction is zero, then the score is by something greater than 0.
assert approx_gte(scores[~pred_is_non_zero], preds[~pred_is_non_zero])

def test_no_predict_proba():

def test_no_predict_proba():
np.random.seed(0)
X = np.random.randn(1_000, 4)
y = ((X[:, 0] > 0) & (X[:, 1] > 0)) * np.abs(X[:, 2] * X[:, 3] ** 2)
Expand All @@ -125,4 +125,3 @@ def test_no_predict_proba():

with pytest.raises(AttributeError, match="This 'ZeroInflatedRegressor' has no attribute 'score_samples'"):
zir.score_samples(X)

0 comments on commit a8c439a

Please sign in to comment.