models.TwoPartFit
A fitted zero-inflated or hurdle model, from ZeroInflated.fit or
Usage
models.TwoPartFit()Hurdle.fit. Methods taking count and zero designs read both parts’ columns by name from count when zero is None.
Attributes
| Name | Description |
|---|---|
| count |
"poisson" or "negative_binomial".
|
| count_coefficients | The count part’s coefficients, on the log scale. |
| covariance |
The covariance of (count, zero, log theta), a list of rows.
|
| fitted | The fitted mean of each row of the data fitted. |
| kind |
"zero_inflated" or "hurdle".
|
| log_likelihoods | Each row’s log-likelihood, without its weight. |
| n_parameters | Both parts’ coefficients and, for the negative binomial, theta. |
| se_log_theta |
The standard error of log(theta), as pscl’s SE.logtheta.
|
| theta |
The negative binomial’s theta, None for the Poisson.
|
| zero_coefficients | The zero part’s coefficients: of the structural zero’s probability |
count
"poisson" or "negative_binomial".
count: str
count_coefficients
The count part’s coefficients, on the log scale.
count_coefficients: list[float]
covariance
The covariance of (count, zero, log theta), a list of rows.
covariance: list[list[float]]
fitted
The fitted mean of each row of the data fitted.
fitted: list[float]
kind
"zero_inflated" or "hurdle".
kind: str
log_likelihoods
Each row’s log-likelihood, without its weight.
log_likelihoods: list[float]
n_parameters
Both parts’ coefficients and, for the negative binomial, theta.
n_parameters: int
se_log_theta
The standard error of log(theta), as pscl’s SE.logtheta.
se_log_theta: float | None
theta
The negative binomial’s theta, None for the Poisson.
theta: float | None
zero_coefficients
The zero part’s coefficients: of the structural zero’s probability
zero_coefficients: list[float]
(zero-inflated) or of P(Y > 0) (hurdle).
Methods
| Name | Description |
|---|---|
| from_json() | Reads an artifact written by to_json. |
| predict() | The expected count of each row. |
| predict_distribution() | Joint draws of the counts: the parameters drawn from the normal |
| prob_zero() |
P(Y = 0) for each row.
|
| probabilities() |
P(Y = k) for k = 0..max_count, one list per row.
|
| to_json() | The fit as a versioned JSON artifact: the kind, the count |
from_json()
Reads an artifact written by to_json.
Usage
from_json(text)Parameters
text: str
Returns
TwoPartFit
Raises
ValueError- For malformed JSON, another format, a newer format version or inconsistent fields.
predict()
The expected count of each row.
Usage
predict(count, zero=None)predict_distribution()
Joint draws of the counts: the parameters drawn from the normal
Usage
predict_distribution(count, n_sims, seed, zero=None)approximation at the maximum, then each row’s count.
Returns
PredictiveDistribution
prob_zero()
P(Y = 0) for each row.
Usage
prob_zero(count, zero=None)probabilities()
P(Y = k) for k = 0..max_count, one list per row.
Usage
probabilities(count, zero=None, max_count=10)to_json()
The fit as a versioned JSON artifact: the kind, the count
Usage
to_json()distribution and zero link, both parts’ names, the parameters and their covariance, the pointwise log-likelihood, the fitted means and the fit statistics; numbers bit for bit (#978). from_json reads it back; pickle uses the same document.
Returns
str
Examples
>>> import pickle
>>> from prospicio.models import Design, Hurdle, TwoPartFit
>>> x = [i % 4 / 3 for i in range(60)]
>>> y = [0.0 if i % 3 == 0 else float(1 + i * 7 % 5) for i in range(60)]
>>> fit = Hurdle().fit(Design([[1.0] * 60, x], ["(Intercept)", "x"]), y)
>>> TwoPartFit.from_json(fit.to_json()).to_json() == fit.to_json()True
>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()True