## models.TwoPartFit


A fitted zero-inflated or hurdle model, from [ZeroInflated.fit](models.ZeroInflated.md#prospicio.models.ZeroInflated.fit) or


Usage

``` python
models.TwoPartFit()
```


[Hurdle.fit](models.Hurdle.md#prospicio.models.Hurdle.fit). Methods taking [count](models.TwoPartFit.md#prospicio.models.TwoPartFit.count) and `zero` designs read both parts' columns by name from [count](models.TwoPartFit.md#prospicio.models.TwoPartFit.count) when `zero` is `None`.


## Attributes

| Name | Description |
|----|----|
| [count](#count) | `"poisson"` or `"negative_binomial"`. |
| [count_coefficients](#count_coefficients) | The count part's coefficients, on the log scale. |
| [covariance](#covariance) | The covariance of `(count, zero, log theta)`, a list of rows. |
| [fitted](#fitted) | The fitted mean of each row of the data fitted. |
| [kind](#kind) | `"zero_inflated"` or `"hurdle"`. |
| [log_likelihoods](#log_likelihoods) | Each row's log-likelihood, without its weight. |
| [n_parameters](#n_parameters) | Both parts' coefficients and, for the negative binomial, [theta](models.TwoPartFit.md#prospicio.models.TwoPartFit.theta). |
| [se_log_theta](#se_log_theta) | The standard error of `log(theta)`, as pscl's `SE.logtheta`. |
| [theta](#theta) | The negative binomial's [theta](models.TwoPartFit.md#prospicio.models.TwoPartFit.theta), `None` for the Poisson. |
| [zero_coefficients](#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](models.TwoPartFit.md#prospicio.models.TwoPartFit.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](models.TwoPartFit.md#prospicio.models.TwoPartFit.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()](#from_json) | Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json). |
| [predict()](#predict) | The expected count of each row. |
| [predict_distribution()](#predict_distribution) | Joint draws of the counts: the parameters drawn from the normal |
| [prob_zero()](#prob_zero) | `P(Y = 0)` for each row. |
| [probabilities()](#probabilities) | `P(Y = k)` for `k = 0..max_count`, one list per row. |
| [to_json()](#to_json) | The fit as a versioned JSON artifact: the kind, the count |

------------------------------------------------------------------------


#### from_json()


Reads an artifact written by [to_json](models.Terms.md#prospicio.models.Terms.to_json).


Usage

``` python
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

``` python
predict(count, zero=None)
```


------------------------------------------------------------------------


#### predict_distribution()


Joint draws of the counts: the parameters drawn from the normal


Usage

``` python
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

``` python
prob_zero(count, zero=None)
```


------------------------------------------------------------------------


#### probabilities()


`P(Y = k)` for `k = 0..max_count`, one list per row.


Usage

``` python
probabilities(count, zero=None, max_count=10)
```


------------------------------------------------------------------------


#### to_json()


The fit as a versioned JSON artifact: the kind, the count


Usage

``` python
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](models.Terms.md#prospicio.models.Terms.from_json) reads it back; `pickle` uses the same document.


##### Returns


`str`  


##### Examples

``` python
>>> 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

``` python
>>> pickle.loads(pickle.dumps(fit)).to_json() == fit.to_json()
```

True
