For StepMixR, please refer to this repository.
A Python package following the scikit-learn API for generalized mixture modeling. The package supports categorical data (Latent Class Analysis) and continuous data (Gaussian Mixtures/Latent Profile Analysis). StepMix can be used for both clustering and supervised learning.
Additional features include:
If you find StepMix useful, please leave a ⭐ and consider citing our arXiv preprint:
@article{morin2023stepmix,
title={StepMix: A Python Package for Pseudo-Likelihood Estimation of Generalized Mixture Models with External Variables},
author={Morin, Sacha and Legault, Robin and Lalibert{\'e}, F{\'e}lix and Bakk, Zsuzsa and Gigu{\`e}re, Charles-{\'E}douard and de la Sablonni{\`e}re, Roxane and Lacourse, {\'E}ric},
journal={arXiv preprint arXiv:2304.03853},
year={2023}
}
You can install StepMix with pip, preferably in a virtual environment:
pip install stepmix
A StepMix mixture using categorical variables on a preloaded data matrix. StepMix accepts either numpy.array
or
pandas.DataFrame
. Categories should be integer-encoded and 0-indexed.
from stepmix.stepmix import StepMix
# Categorical StepMix Model with 3 latent classes
model = StepMix(n_components=3, measurement="categorical")
model.fit(data)
# Allow missing values
model_nan = StepMix(n_components=3, measurement="categorical_nan")
model_nan.fit(data_nan)
For binary data you can also use measurement="binary"
or measurement="binary_nan"
. For continuous data, you can fit a Gaussian Mixture with diagonal covariances using measurement="continuous"
or measurement="continuous_nan"
.
Set verbose=1
for a detailed output.
Please refer to the StepMix tutorials to learn how to combine continuous and categorical data in the same model.
Detailed tutorials are available in notebooks:
n_components
) with cross-validation;