<a id="skfolio-distribution-studentt"></a>

# skfolio.distribution.StudentT

<a id="skfolio.distribution.StudentT"></a>

### *class* skfolio.distribution.StudentT(loc=None, scale=None, random_state=None)

Student’s t Distribution Estimation.

This estimator fits a univariate Student’s t distribution to the input data.

The probability density function is:

$$
f(x, \nu) = \frac{\Gamma((\nu+1)/2)}
                {\sqrt{\pi \nu} \Gamma(\nu/2)}
            (1+x^2/\nu)^{-(\nu+1)/2}
$$

where $x$ is a real number and the degrees of freedom parameter $\nu$
(denoted `dof` in the implementation) satisfies $\nu > 0$. $\Gamma$ is
the gamma function (`scipy.special.gamma`).

The probability density above is defined in the “standardized” form. To shift
and/or scale the distribution use the loc and scale parameters. Specifically,
`pdf(x, df, loc, scale)` is equivalent to `pdf(y, df) / scale` with
`y = (x - loc) / scale`.

For more information, you can refer to the [scipy documentation](https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.t.html#scipy.stats.t)

* **Parameters:**
  **loc** *float or None, default=None*
  : If provided, the location parameter is fixed to this value during fitting.
    Otherwise, it is estimated from the data.

  **scale** *float or None, default=None*
  : If provided, the scale parameter is fixed to this value during fitting.
    Otherwise, it is estimated from the data.

  **random_state** *int, RandomState instance or None, default=None*
  : Seed or random state to ensure reproducibility.
* **Attributes:**
  **dof_** *float*
  : The fitted degrees of freedom for the Student’s t distribution.

  **loc_** *float*
  : The fitted location parameter.

  **scale_** *float*
  : The fitted scale parameter.

### Methods

| [`aic`](#skfolio.distribution.StudentT.aic)(X)                 | Compute the Akaike Information Criterion (AIC) for the model given data X.             |
|-------------------------------------------------------------------------|----------------------------------------------------------------------------------------|
| [`bic`](#skfolio.distribution.StudentT.bic)(X)                 | Compute the Bayesian Information Criterion (BIC) for the model given data X.           |
| [`cdf`](#skfolio.distribution.StudentT.cdf)(X)                 | Compute the cumulative distribution function (CDF) for the given data.                 |
| [`fit`](#skfolio.distribution.StudentT.fit)(X[, y])            | Fit the univariate Student's t distribution model.                                     |
| [`get_metadata_routing`](#skfolio.distribution.StudentT.get_metadata_routing)() | Get metadata routing of this object.                                                   |
| [`get_params`](#skfolio.distribution.StudentT.get_params)([deep])     | Get parameters for this estimator.                                                     |
| [`plot_pdf`](#skfolio.distribution.StudentT.plot_pdf)([X, title])   | Plot the probability density function (PDF).                                           |
| [`ppf`](#skfolio.distribution.StudentT.ppf)(X)                 | Compute the percent point function (inverse of the CDF) for the given                  |
| [`qq_plot`](#skfolio.distribution.StudentT.qq_plot)(X[, title])    | Plot the empirical quantiles of the sample X versus the quantiles of the fitted model. |
| [`sample`](#skfolio.distribution.StudentT.sample)([n_samples])    | Generate random samples from the fitted distribution.                                  |
| [`score`](#skfolio.distribution.StudentT.score)(X[, y])          | Compute the total log-likelihood under the model.                                      |
| [`score_samples`](#skfolio.distribution.StudentT.score_samples)(X)       | Compute the log-likelihood of each sample (log-pdf) under the model.                   |
| [`set_params`](#skfolio.distribution.StudentT.set_params)(\*\*params) | Set the parameters of this estimator.                                                  |

### Examples

```pycon
>>> from skfolio.datasets import load_sp500_index
>>> from skfolio.preprocessing import prices_to_returns
>>> from skfolio.distribution.univariate import StudentT
>>>
>>> # Load historical prices and convert them to returns
>>> prices = load_sp500_index()
>>> X = prices_to_returns(prices)
>>>
>>> # Initialize the estimator.
>>> model = StudentT()
>>>
>>> # Fit the model to the data.
>>> model.fit(X)
StudentT(...)
>>>
>>> # Display the fitted parameters.
>>> print(model.fitted_repr)
StudentT(loc=0.00062, scale=0.0068, df=2.7)
>>>
>>> # Compute the log-likelihood, total log-likelihood, CDF, PPF, AIC, and BIC
>>> log_likelihood = model.score_samples(X)
>>> score = model.score(X)
>>> cdf = model.cdf(X)
>>> ppf = model.ppf([0.01, 0.05, 0.5, 0.95, 0.99])
>>> aic = model.aic(X)
>>> bic = model.bic(X)
>>>
>>> # Generate 5 new samples from the fitted distribution.
>>> samples = model.sample(n_samples=5)
>>>
>>> # Plot the estimated probability density function (PDF).
>>> fig = model.plot_pdf()
```

<a id="skfolio.distribution.StudentT.aic"></a>

#### aic(X)

Compute the Akaike Information Criterion (AIC) for the model given data X.

The AIC is defined as:

$$
\mathrm{AIC} = -2 \, \log L \;+\; 2 k,

$$

where

- $\log L$ is the total log-likelihood
- $k$ is the number of parameters in the model

A lower AIC value indicates a better trade-off between model fit and complexity.

* **Parameters:**
  **X** *array-like of shape (n_observations, n_features)*
  : The input data on which to compute the AIC.
* **Returns:**
  **aic** *float*
  : The AIC of the fitted model on the given data.

### Notes

In practice, both AIC and BIC measure the trade-off between model fit and
complexity, but BIC tends to prefer simpler models for large $n$
because of the $\ln(n)$ term.

### References

* <a id='r219c46e80256-1'>**[1]**</a> “A new look at the statistical model identification”, Akaike (1974).

<a id="skfolio.distribution.StudentT.bic"></a>

#### bic(X)

Compute the Bayesian Information Criterion (BIC) for the model given data X.

The BIC is defined as:

$$
\mathrm{BIC} = -2 \, \log L \;+\; k \,\ln(n),

$$

where

- $\log L$ is the (maximized) total log-likelihood
- $k$ is the number of parameters in the model
- $n$ is the number of observations

A lower BIC value suggests a better fit while imposing a stronger penalty
for model complexity than the AIC.

* **Parameters:**
  **X** *array-like of shape (n_observations, n_features)*
  : The input data on which to compute the BIC.
* **Returns:**
  **bic** *float*
  : The BIC of the fitted model on the given data.

### Notes

In practice, both AIC and BIC measure the trade-off between model fit and
complexity, but BIC tends to prefer simpler models for large $n$
because of the $\ln(n)$ term.

### References

* <a id='r6f1d052b627f-1'>**[1]**</a> “Estimating the dimension of a model”, Schwarz, G. (1978).

<a id="skfolio.distribution.StudentT.cdf"></a>

#### cdf(X)

Compute the cumulative distribution function (CDF) for the given data.

* **Parameters:**
  **X** *array-like of shape (n_observations, 1)*
  : Data points at which to evaluate the CDF.
* **Returns:**
  **cdf** *ndarray of shape (n_observations, 1)*
  : The CDF evaluated at each data point.

<a id="skfolio.distribution.StudentT.fit"></a>

#### fit(X, y=None)

Fit the univariate Student’s t distribution model.

* **Parameters:**
  **X** *array-like of shape (n_observations, 1)*
  : The input data. X must contain a single column.

  **y** *None*
  : Ignored. Provided for compatibility with scikit-learn’s API.
* **Returns:**
  **self** *StudentT*
  : Returns the instance itself.

<a id="skfolio.distribution.StudentT.fitted_repr"></a>

#### *property* fitted_repr

String representation of the fitted univariate distribution.

<a id="skfolio.distribution.StudentT.get_metadata_routing"></a>

#### get_metadata_routing()

Get metadata routing of this object.

Please check [User Guide](https://skfolio.org/user_guide/metadata_routing.html.md#metadata-routing) on how the routing
mechanism works.

* **Returns:**
  **routing** *MetadataRequest*
  : A `MetadataRequest` encapsulating
    routing information.

<a id="skfolio.distribution.StudentT.get_params"></a>

#### get_params(deep=True)

Get parameters for this estimator.

* **Parameters:**
  **deep** *bool, default=True*
  : If True, will return the parameters for this estimator and
    contained subobjects that are estimators.
* **Returns:**
  **params** *dict*
  : Parameter names mapped to their values.

<a id="skfolio.distribution.StudentT.n_params"></a>

#### *property* n_params

Number of model parameters.

<a id="skfolio.distribution.StudentT.plot_pdf"></a>

#### plot_pdf(X=None, title=None)

Plot the probability density function (PDF).

* **Parameters:**
  **X** *array-like of shape (n_samples, 1), optional*
  : If provided, it is used to plot the empirical data KDE for comparison
    versus the model PDF.

  **title** *str, optional*
  : The title for the plot. If not provided, a default title based on the fitted
    model’s representation is used.
* **Returns:**
  **fig** *go.Figure*
  : A Plotly figure object containing the PDF plot.

<a id="skfolio.distribution.StudentT.ppf"></a>

#### ppf(X)

Compute the percent point function (inverse of the CDF) for the given
: probabilities.

* **Parameters:**
  **X** *array-like of shape (n_observations, 1)*
  : Probabilities for which to compute the corresponding quantiles.
* **Returns:**
  **ppf** *ndarray of shape (n_observations, 1)*
  : The quantiles corresponding to the given probabilities.

<a id="skfolio.distribution.StudentT.qq_plot"></a>

#### qq_plot(X, title=None)

Plot the empirical quantiles of the sample X versus the quantiles of the
fitted model.

* **Parameters:**
  **X** *array-like of shape (n_samples, 1), optional*
  : Used to plot the empirical quantiles for comparison versus the model
    quantiles.

  **title** *str, optional*
  : The title for the plot. If not provided, a default title based on the fitted
    model’s representation is used.
* **Returns:**
  **fig** *go.Figure*
  : A Plotly figure object containing the PDF plot.

<a id="skfolio.distribution.StudentT.sample"></a>

#### sample(n_samples=1)

Generate random samples from the fitted distribution.

Currently, this is implemented only for gaussian and tophat kernels.

* **Parameters:**
  **n_samples** *int, default=1*
  : Number of samples to generate.
* **Returns:**
  **X** *array-like of shape (n_samples, 1)*
  : List of samples.

<a id="skfolio.distribution.StudentT.score"></a>

#### score(X, y=None)

Compute the total log-likelihood under the model.

* **Parameters:**
  **X** *array-like of shape (n_observations, n_features)*
  : An array of data points for which the total log-likelihood is computed.

  **y** *None*
  : Ignored. Provided for compatibility with scikit-learn’s API.
* **Returns:**
  **logprob** *float*
  : The total log-likelihood (sum of log-pdf values).

<a id="skfolio.distribution.StudentT.score_samples"></a>

#### score_samples(X)

Compute the log-likelihood of each sample (log-pdf) under the model.

* **Parameters:**
  **X** *array-like of shape (n_observations, 1)*
  : An array of points at which to evaluate the log-probability density.
    The data should be a single feature column.
* **Returns:**
  **density** *ndarray of shape (n_observations,)*
  : Log-likelihood values for each observation in X.

<a id="skfolio.distribution.StudentT.set_params"></a>

#### set_params(\*\*params)

Set the parameters of this estimator.

The method works on simple estimators as well as on nested objects
(such as `Pipeline`). The latter have
parameters of the form `<component>__<parameter>` so that it’s
possible to update each component of a nested object.

* **Parameters:**
  **\*\*params** *dict*
  : Estimator parameters.
* **Returns:**
  **self** *estimator instance*
  : Estimator instance.

