Skip to content
Open
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: 4 additions & 3 deletions pygam/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Core Classes"""

import numpy as np
from copy import deepcopy

from pygam.utils import flatten, round_to_n_decimal_places

Expand Down Expand Up @@ -150,15 +151,15 @@ def get_params(self, deep=False):
-------
dict
"""
attrs = self.__dict__
attrs =deepcopy(self.__dict__)
for attr in self._include:
attrs[attr] = getattr(self, attr)
attrs[attr] = deepcopy(getattr(self, attr))

if deep is True:
return attrs
return dict(
[
(k, v)
(k, deepcopy(v))
for k, v in list(attrs.items())
if (k[0] != "_") and (k[-1] != "_") and (k not in self._exclude)
]
Expand Down
14 changes: 13 additions & 1 deletion pygam/pygam.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import scipy as sp
from progressbar import ProgressBar
from scipy import stats # noqa: F401
from sklearn.base import BaseEstimator

from pygam.callbacks import (
CALLBACKS, # noqa: F401
Expand Down Expand Up @@ -175,7 +176,9 @@ def __init__(
self.link = link
self.callbacks = callbacks
self.verbose = verbose
self.terms = TermList(terms) if isinstance(terms, Term) else terms
self.terms = terms # store original input for get_params()
self._terms = TermList(terms) if isinstance(terms, Term) else terms # internal processed version

self.fit_intercept = fit_intercept

for k, v in kwargs.items():
Expand Down Expand Up @@ -207,6 +210,14 @@ def __init__(
# self.terms.lam = value
# else:
# self._lam = value
def _get_tags(self):
"""Required for sklearn compatibility"""
return {
"requires_y": True,
"non_deterministic": False,
"requires_positive_y": False,
}


@property
def _is_fitted(self):
Expand Down Expand Up @@ -856,6 +867,7 @@ def _on_loop_end(self, variables):
for callback in self.callbacks:
if hasattr(callback, "on_loop_end"):
self.logs_[str(callback)].append(callback.on_loop_end(**variables))


def fit(self, X, y, weights=None):
"""Fit the generalized additive model.
Expand Down
3 changes: 3 additions & 0 deletions test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from pygam import LinearGAM
gam = LinearGAM()
print(gam._get_tags())
14 changes: 14 additions & 0 deletions test1.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pygam import LinearGAM

gam = LinearGAM()

params = gam.get_params()

print("Before change:", params["callbacks"])

# Try modifying returned params
params["callbacks"].append("hack")

# Check again
params2 = gam.get_params()
print("After change:", params2["callbacks"])
10 changes: 10 additions & 0 deletions test2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import numpy as np
from pygam import LinearGAM

X = np.random.rand(100, 1)
y = np.sin(X[:, 0])

gam = LinearGAM().fit(X, y)
params = gam.get_params()

print("coef_ in params:", "coef_" in params)