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 pyGAM to work with SkLearn GridSearchCV #267

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 21 additions & 10 deletions pygam/pygam.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class GAM(Core, MetaTermMixin):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs']` will be used.

distribution : str or Distribution object, optional
Distribution to use in the model.
Expand Down Expand Up @@ -149,14 +150,14 @@ class GAM(Core, MetaTermMixin):
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
distribution='normal', link='identity',
callbacks=['deviance', 'diffs'],
callbacks=None,
fit_intercept=True, verbose=False, **kwargs):

self.max_iter = max_iter
self.tol = tol
self.distribution = distribution
self.link = link
self.callbacks = callbacks
self.callbacks = callbacks or ['deviance', 'diffs']
self.verbose = verbose
self.terms = TermList(terms) if isinstance(terms, Term) else terms
self.fit_intercept = fit_intercept
Expand Down Expand Up @@ -2234,6 +2235,7 @@ class LinearGAM(GAM):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs']` will be used.

fit_intercept : bool, optional
Specifies if a constant (a.k.a. bias or intercept) should be
Expand Down Expand Up @@ -2279,14 +2281,16 @@ class LinearGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
scale=None, callbacks=['deviance', 'diffs'],
scale=None, callbacks=None,
fit_intercept=True, verbose=False, **kwargs):
callbacks = callbacks or ['deviance', 'diffs']
self.scale = scale
super(LinearGAM, self).__init__(terms=terms,
distribution=NormalDist(scale=self.scale),
link='identity',
max_iter=max_iter,
tol=tol,
callbacks=callbacks,
fit_intercept=fit_intercept,
verbose=verbose,
**kwargs)
Expand Down Expand Up @@ -2354,6 +2358,7 @@ class LogisticGAM(GAM):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs', 'accuracy']` will be used.

fit_intercept : bool, optional
Specifies if a constant (a.k.a. bias or intercept) should be
Expand Down Expand Up @@ -2399,9 +2404,9 @@ class LogisticGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
callbacks=['deviance', 'diffs', 'accuracy'],
callbacks=None,
fit_intercept=True, verbose=False, **kwargs):

self.callbacks = callbacks or ['deviance', 'diffs', 'accuracy']
# call super
super(LogisticGAM, self).__init__(terms=terms,
distribution='binomial',
Expand Down Expand Up @@ -2565,9 +2570,9 @@ class PoissonGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
callbacks=['deviance', 'diffs'],
callbacks=None,
fit_intercept=True, verbose=False, **kwargs):

callbacks = callbacks or ['deviance', 'diffs', 'accuracy']
# call super
super(PoissonGAM, self).__init__(terms=terms,
distribution='poisson',
Expand Down Expand Up @@ -2868,6 +2873,7 @@ class GammaGAM(GAM):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs']` will be used.

fit_intercept : bool, optional
Specifies if a constant (a.k.a. bias or intercept) should be
Expand Down Expand Up @@ -2913,8 +2919,9 @@ class GammaGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
scale=None, callbacks=['deviance', 'diffs'],
scale=None, callbacks=None,
fit_intercept=True, verbose=False, **kwargs):
callbacks = callbacks or ['deviance', 'diffs']
self.scale = scale
super(GammaGAM, self).__init__(terms=terms,
distribution=GammaDist(scale=self.scale),
Expand Down Expand Up @@ -2976,6 +2983,7 @@ class InvGaussGAM(GAM):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs']` will be used.

fit_intercept : bool, optional
Specifies if a constant (a.k.a. bias or intercept) should be
Expand Down Expand Up @@ -3021,8 +3029,9 @@ class InvGaussGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
scale=None, callbacks=['deviance', 'diffs'],
scale=None, callbacks=None,
fit_intercept=True, verbose=False, **kwargs):
callbacks = callbacks or ['deviance', 'diffs']
self.scale = scale
super(InvGaussGAM, self).__init__(terms=terms,
distribution=InvGaussDist(scale=self.scale),
Expand Down Expand Up @@ -3074,6 +3083,7 @@ class ExpectileGAM(GAM):

callbacks : list of str or list of CallBack objects, optional
Names of callback objects to call during the optimization loop.
By default `['deviance', 'diffs']` will be used.

fit_intercept : bool, optional
Specifies if a constant (a.k.a. bias or intercept) should be
Expand Down Expand Up @@ -3119,8 +3129,9 @@ class ExpectileGAM(GAM):
http://www.ibschannel2015.nl/project/userfiles/Crash_course_handout.pdf
"""
def __init__(self, terms='auto', max_iter=100, tol=1e-4,
scale=None, callbacks=['deviance', 'diffs'],
scale=None, callbacks=None,
fit_intercept=True, expectile=0.5, verbose=False, **kwargs):
callbacks = callbacks or ['deviance', 'diffs']
self.scale = scale
self.expectile = expectile
super(ExpectileGAM, self).__init__(terms=terms,
Expand Down