Model
Models for the joint distribution of weekly calendar data.
model = LatentCalendar(n_components=3, random_state=42)
X = df_wide.to_numpy()
model.fit(X)
X_latent = model.transform(X)
X_pred = model.predict(X)
ConjugateModel
Bases: BaseEstimator
, TransformerMixin
Conjugate model for the calendar joint distribution.
This is a wrapper around the conjugate model for the multinomial distribution. It is a wrapper around the Dirichlet distribution.
This doesn't use dimensionality reduction, but it does use the conjugate model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
a
|
ndarray | None
|
(n_times,) prior for each hour of the day. If None, then the prior is the average of the data. |
None
|
Source code in latent_calendar/model/latent_calendar.py
DummyModel
Bases: LatentCalendar
Return even probability of a latent.
This can be used as the worse possible baseline.
Source code in latent_calendar/model/latent_calendar.py
create()
classmethod
fit(X, y=None)
All components are equal probabilty of every hour.
Source code in latent_calendar/model/latent_calendar.py
from_prior(prior)
classmethod
Return a dummy model from a prior.
transform(X, y=None)
Everyone has equal probability of being in each group.
LatentCalendar
Bases: LatentDirichletAllocation
Model weekly calendar data as a mixture of multinomial distributions.
Adapted from sklearn's Latent Dirichlet Allocation model.
Provides a predict
method that returns the marginal probability of each time slot for a given row and
a transform
method that returns the latent representation of each row.
Source code in latent_calendar/model/latent_calendar.py
component_distribution_: np.ndarray
property
Population frequency of each component.
normalized_components_: np.ndarray
property
Components that each sum to 1.
joint_distribution(X_latent)
predict(X, y=None)
Return the marginal probabilities for a given row.
Marginalize out the loads via law of total probability
Source code in latent_calendar/model/latent_calendar.py
MarginalModel
Bases: LatentCalendar
Source code in latent_calendar/model/latent_calendar.py
fit(X, y=None)
transform(X, y=None)
constant_prior(X, value=1.0)
Return the prior for each hour of the day.
This is the average of all the rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
(nrows, n_times) |
required |
Source code in latent_calendar/model/latent_calendar.py
hourly_prior(X)
Return the prior for each hour of the day.
This is the average of all the rows.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
X
|
ndarray
|
(nrows, n_times) |
required |
Returns:
Type | Description |
---|---|
ndarray
|
(n_times,) |
Source code in latent_calendar/model/latent_calendar.py
predict_on_dataframe(df, model)
Small wrapper to predict on DataFrame and keep same columns and index.
Source code in latent_calendar/model/utils.py
transform_on_dataframe(df, model)
Small wrapper to transform on DataFrame and keep index.