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
54 changes: 54 additions & 0 deletions statsmodels/base/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,60 @@ def fit(self, start_params=None, method='newton', maxiter=100,
mlefit.mle_settings = optim_settings
return mlefit

def solution_path(self, maxvar=None, wt_vec=None, min_pwt=0.,
param_threshold=1e-4, xtol=1., **fit_args):
"""
Returns the solution path for the regularized fit
of the model.

Parameters:
-----------
maxvar : integer
The maximum number of variables in the model. If
None, `maxvar` is the number of columns in exog (see
notes).
wt_vec : array-like
A vector of the same length as params, containing
penalty weights for each coefficient.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs explanation that this is proportionally changed along the solution path, with minimum min_pwt * wt_vec

min_pwt : float
The minimum penalty weight that is considered.
param_threshold : float
Coefficients smaller in magnitude than this value
are considered to be equal to zero.
xtol : float
The penalty weight where each parameter becomes zero is
calculated to this level of precision.
fit_args : additional keyword arguments
Arguments passed to `fit_regularized`.

Returns:
--------
A SolutionPathResults object.

Notes:
------
Some models on the solution path may have more than `maxvar`
variables, but only the part of the solution path containing
models with at most `maxvar` variables is thoroughly explored.
"""

from solution_path import SolutionPath, SolutionPathResults

# Since we are fitting so many models, it is not helpful to
# have all the optimization details go to stdout.
if 'disp' not in fit_args:
fit_args['disp'] = False

spa = SolutionPath(self, maxvar, wt_vec, param_threshold,
min_pwt, **fit_args)
spa.initialize()
spa.refine()

spr = SolutionPathResults(self, wt_vec, np.asarray(spa.weights),
spa.ix_nonzero, spa.params)

return spr


def _fit_mle_newton(f, score, start_params, fargs, kwargs, disp=True,
maxiter=100, callback=None, retall=False,
Expand Down
Loading