Skip to content

Commit b3c5e27

Browse files
authored
Merge pull request statsmodels#6031 from bashtage/check-docstring-ols
DOC: Fix regression doc strings
2 parents 0367037 + 68cc2e4 commit b3c5e27

File tree

8 files changed

+591
-408
lines changed

8 files changed

+591
-408
lines changed
109 KB
Loading

docs/source/conf.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,16 @@
341341
# numpydoc_show_class_members = False
342342
# numpydoc_show_inherited_class_members = True
343343

344+
# Create xrefs
345+
numpydoc_xref_param_type = True
346+
347+
# Example configuration for intersphinx: refer to the Python standard library.
344348
# Example configuration for intersphinx: refer to the Python standard library.
345349
intersphinx_mapping = {
346-
'numpy': ('https://docs.scipy.org/doc/numpy/', None),
347-
'python': ('https://docs.python.org/3/', None),
348-
'pydagogue': ('https://matthew-brett.github.io/pydagogue/', None),
349-
'patsy': ('https://patsy.readthedocs.io/en/latest/', None),
350+
'matplotlib': ('https://matplotlib.org/', None),
351+
'scipy': ('https://docs.scipy.org/doc/scipy/reference/', None),
352+
'python': ('https://docs.python.org/3', None),
353+
'numpy': ('https://docs.scipy.org/doc/numpy', None),
350354
'pandas': ('https://pandas.pydata.org/pandas-docs/stable/', None),
351355
}
352356

docs/source/examples/landing.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,11 @@
176176
"text": "Exponential Smoothing",
177177
"target": "notebooks/generated/exponential_smoothing.html",
178178
"img": "../_static/images/exponential_smoothing.png"
179+
},
180+
{
181+
"text": "Seasonal Decomposition",
182+
"target": "notebooks/generated/stl_decomposition.html",
183+
"img": "../_static/images/stl_decomposition.png"
179184
}
180185
]
181186
},

docs/source/regression.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,13 @@ results class of the other linear models.
203203
OLSResults
204204
PredictionResults
205205

206+
.. currentmodule:: statsmodels.base.elastic_net
207+
208+
.. autosummary::
209+
:toctree: generated/
210+
211+
RegularizedResults
212+
206213
.. currentmodule:: statsmodels.regression.quantile_regression
207214

208215
.. autosummary::

statsmodels/base/elastic_net.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,12 +350,24 @@ def _opt_1d(func, grad, hess, model, start, L1_wt, tol,
350350

351351

352352
class RegularizedResults(Results):
353+
"""
354+
Results for models estimated using regularization
353355
356+
Parameters
357+
----------
358+
model : Model
359+
The model instance used to estimate the parameters.
360+
params : ndarray
361+
The estimated (regularized) parameters.
362+
"""
354363
def __init__(self, model, params):
355364
super(RegularizedResults, self).__init__(model, params)
356365

357366
@cache_readonly
358367
def fittedvalues(self):
368+
"""
369+
The predicted values from the model at the estimated parameters.
370+
"""
359371
return self.model.predict(self.params)
360372

361373

statsmodels/base/model.py

Lines changed: 52 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
from statsmodels.base.optimizer import Optimizer
2020

2121

22-
_model_params_doc = """
23-
Parameters
22+
_model_params_doc = """Parameters
2423
----------
2524
endog : array_like
26-
1-d endogenous response variable. The dependent variable.
25+
A 1-d endogenous response variable. The dependent variable.
2726
exog : array_like
2827
A nobs x k array where `nobs` is the number of observations and `k`
2928
is the number of regressors. An intercept is not included by default
@@ -34,14 +33,16 @@
3433
missing : str
3534
Available options are 'none', 'drop', and 'raise'. If 'none', no nan
3635
checking is done. If 'drop', any observations with nans are dropped.
37-
If 'raise', an error is raised. Default is 'none.'"""
36+
If 'raise', an error is raised. Default is 'none'."""
3837
_extra_param_doc = """
3938
hasconst : None or bool
4039
Indicates whether the RHS includes a user-supplied constant. If True,
4140
a constant is not checked for and k_constant is set to 1 and all
4241
result statistics are calculated as if a constant is present. If
4342
False, a constant is not checked for and k_constant is set to 0.
44-
"""
43+
**kwargs
44+
Extra arguments that are used to set model properties when using the
45+
formula interface."""
4546

4647

4748
class Model(object):
@@ -117,19 +118,19 @@ def from_formula(cls, formula, data, subset=None, drop_cols=None,
117118
Parameters
118119
----------
119120
formula : str or generic Formula object
120-
The formula specifying the model
121+
The formula specifying the model.
121122
data : array_like
122123
The data for the model. See Notes.
123124
subset : array_like
124125
An array-like object of booleans, integers, or index values that
125126
indicate the subset of df to use in the model. Assumes df is a
126-
`pandas.DataFrame`
127+
`pandas.DataFrame`.
127128
drop_cols : array_like
128129
Columns to drop from the design matrix. Cannot be used to
129130
drop terms involving categoricals.
130-
args : extra arguments
131-
These are passed to the model
132-
kwargs : extra keyword arguments
131+
*args
132+
Additional positional argument that are passed to the model.
133+
**kwargs
133134
These are passed to the model with one exception. The
134135
``eval_env`` keyword is passed to patsy. It can be either a
135136
:class:`patsy:patsy.EvalEnvironment` object or an integer
@@ -139,7 +140,8 @@ def from_formula(cls, formula, data, subset=None, drop_cols=None,
139140
140141
Returns
141142
-------
142-
model : Model instance
143+
model
144+
The model instance.
143145
144146
Notes
145147
-----
@@ -198,12 +200,16 @@ def from_formula(cls, formula, data, subset=None, drop_cols=None,
198200

199201
@property
200202
def endog_names(self):
201-
"""Names of endogenous variables"""
203+
"""
204+
Names of endogenous variables.
205+
"""
202206
return self.data.ynames
203207

204208
@property
205209
def exog_names(self):
206-
"""Names of exogenous variables"""
210+
"""
211+
Names of exogenous variables.
212+
"""
207213
return self.data.xnames
208214

209215
def fit(self):
@@ -232,9 +238,11 @@ def __init__(self, endog, exog=None, **kwargs):
232238

233239
def initialize(self):
234240
"""
235-
Initialize (possibly re-initialize) a Model instance. For
236-
instance, the design matrix of a linear model may change
237-
and some things must be recomputed.
241+
Initialize (possibly re-initialize) a Model instance.
242+
243+
For example, if the the design matrix of a linear model changes then
244+
initialized can be used to recompute values using the modified design
245+
matrix.
238246
"""
239247
pass
240248

@@ -252,20 +260,45 @@ def score(self, params):
252260
Score vector of model.
253261
254262
The gradient of logL with respect to each parameter.
263+
264+
Parameters
265+
----------
266+
params : ndarray
267+
The parameters to use when evaluating the Hessian.
268+
269+
Returns
270+
-------
271+
ndarray
272+
The score vector evaluated at the parameters.
255273
"""
256274
raise NotImplementedError
257275

258276
def information(self, params):
259277
"""
260-
Fisher information matrix of model
278+
Fisher information matrix of model.
261279
262-
Returns -Hessian of loglike evaluated at params.
280+
Returns -1 * Hessian of the log-loglikelihood evaluated at params.
281+
282+
Parameters
283+
----------
284+
params : ndarray
285+
The model parameters.
263286
"""
264287
raise NotImplementedError
265288

266289
def hessian(self, params):
267290
"""
268-
The Hessian matrix of the model
291+
The Hessian matrix of the model.
292+
293+
Parameters
294+
----------
295+
params : ndarray
296+
The parameters to use when evaluating the Hessian.
297+
298+
Returns
299+
-------
300+
ndarray
301+
The hessian evaluated at the parameters.
269302
"""
270303
raise NotImplementedError
271304

statsmodels/regression/_prediction.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def summary_frame(self, what='all', alpha=0.05):
9595
def get_prediction(self, exog=None, transform=True, weights=None,
9696
row_labels=None, pred_kwds=None):
9797
"""
98-
compute prediction results
98+
Compute prediction results.
9999
100100
Parameters
101101
----------
@@ -111,13 +111,16 @@ def get_prediction(self, exog=None, transform=True, weights=None,
111111
weights : array_like, optional
112112
Weights interpreted as in WLS, used for the variance of the predicted
113113
residual.
114-
args, kwargs :
115-
Some models can take additional arguments or keywords, see the
116-
predict method of the model for the details.
114+
row_labels : list
115+
A list of row labels to use. If not provided, read `exog` is
116+
available.
117+
**kwargs
118+
Some models can take additional keyword arguments, see the predict
119+
method of the model for the details.
117120
118121
Returns
119122
-------
120-
prediction_results : linear_model.PredictionResults
123+
linear_model.PredictionResults
121124
The prediction results instance contains prediction and prediction
122125
variance and can on demand calculate confidence intervals and summary
123126
tables for the prediction of the mean and of new observations.

0 commit comments

Comments
 (0)