# multiviewstacking: a python implementation of the Multi-View Stacking algorithm <img src="https://github.com/enriquegit/multiviewstacking/blob/main/img/logo60-50.png?raw=true" align="right" width="300px " alt=""/>
Multi-View learning algorithms aim to learn from different representational views. For example, a movie can be represented by three views. The sequence of images, the audio, and the subtitles. Instead of concatenating the features of every view and training a single model, the Multi-View Stacking algorithm[1] builds independent (and possibly of different types) models for each view. These models are called *first-level-learners*. Then, the class and score predictions of the first-level-learners are used as features to train another model called the *meta-learner*. This approach is based on the Stacked Generalization method proposed by Wolpert D. H.[2].
The `multiviewstacking` package provides the following functionalities:
* Train Multi-View Stacking classifiers.
* Supports arbitrary number of views. The limit is your computer's memory.
* Use any scikit-learn classifier as first-level-learner and meta-learner.
* Use any custom model as long as they implement the `fit()`, `predict()`, and `predict_proba()` methods.
* Combine different types of first-level-learners.
* Comes with a pre-loaded dataset with two views for testing.
## Requirements
- Python 3.8+
- pandas
- numpy
- scikit-learn >= 1.2.2
## Installation
You can install the `multiviewstacking` package with:
```
pip install multiviewstacking
```
## Quick start example
This quick start example shows you how to train a multi-view model. For more detailed tutorials, check the jupyter notebooks in the [/examples](https://github.com/enriquegit/multiviewstacking/tree/main/examples) directory.
```python
import numpy as np
from multiviewstacking import load_example_data
from multiviewstacking import MultiViewStacking
from sklearn.ensemble import RandomForestClassifier
# Load the built-in example dataset.
(xtrain,ytrain,xtest,ytest,ind1,ind2,l) = load_example_data()
```
The built-in dataset contains features for two views (audio, accelerometer) for activity recognition.
The `load_example_data()` method returns a tuple with the train and test sets. It also returns the column indices for the two views and a LabelEnconder to convert the classes from integers back to strings.
```python
# Define two first-level-learners and the meta-learner.
# All of them are Random Forests but they can be any other model.
m_v1 = RandomForestClassifier(n_estimators=50, random_state=123)
m_v2 = RandomForestClassifier(n_estimators=50, random_state=123)
m_meta = RandomForestClassifier(n_estimators=50, random_state=123)
# Train the model.
model = MultiViewStacking(views_indices = [ind1, ind2],
first_level_learners = [m_v1, m_v2],
meta_learner = m_meta)
```
The `view_indices` parameter is a list of lists. Each list specifies the column indices of the train set for each view.
In this case `ind1` stores the indices of the audio features and `ind2` contains the indices of the accelerometer features.
Th `first_level_learners` parameter is a list of scikit-learn models or any other custom models. The `meta-learnr` specifies the model to be used as the meta-learner.
```python
# Train the model.
model.fit(xtrain, ytrain)
# Make predictions on the test set.
preds = model.predict(xtest)
# Compuet the accuracy.
np.sum(ytest == preds) / len(ytest)
```
## Citation
To cite this package use:
```{r}
Enrique Garcia-Ceja (2024). multiviewstacking: A python implementation of the Multi-View Stacking algorithm.
Python package https://github.com/enriquegit/multiviewstacking
```
BibTex entry for LaTeX:
```{r}
@Manual{MVS,
title = {multiviewstacking: A python implementation of the Multi-View Stacking algorithm},
author = {Enrique Garcia-Ceja},
year = {2024},
note = {Python package},
url = {https://github.com/enriquegit/multiviewstacking}
}
```
## References
[1] Garcia-Ceja, Enrique, et al. "Multi-view stacking for activity recognition with sound and accelerometer data." Information Fusion 40 (2018): 45-56.
[2] Wolpert, D. H. (1992). Stacked generalization. Neural networks, 5(2), 241-259.
Raw data
{
"_id": null,
"home_page": "https://github.com/enriquegit/multiviewstacking",
"name": "multiviewstacking",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "multi-view stacking, machine learning, classification, sensor fusion",
"author": "Enrique Garcia-Ceja",
"author_email": "e.g.mx@ieee.org",
"download_url": "https://files.pythonhosted.org/packages/0a/a7/90048c9e15dfbf7f8093226d9e383c433ace82154d27ff369b61e322e059/multiviewstacking-0.5.0.tar.gz",
"platform": null,
"description": "# multiviewstacking: a python implementation of the Multi-View Stacking algorithm <img src=\"https://github.com/enriquegit/multiviewstacking/blob/main/img/logo60-50.png?raw=true\" align=\"right\" width=\"300px \" alt=\"\"/>\r\n\r\n\r\n\r\nMulti-View learning algorithms aim to learn from different representational views. For example, a movie can be represented by three views. The sequence of images, the audio, and the subtitles. Instead of concatenating the features of every view and training a single model, the Multi-View Stacking algorithm[1] builds independent (and possibly of different types) models for each view. These models are called *first-level-learners*. Then, the class and score predictions of the first-level-learners are used as features to train another model called the *meta-learner*. This approach is based on the Stacked Generalization method proposed by Wolpert D. H.[2].\r\n\r\nThe `multiviewstacking` package provides the following functionalities:\r\n\r\n* Train Multi-View Stacking classifiers.\r\n* Supports arbitrary number of views. The limit is your computer's memory.\r\n* Use any scikit-learn classifier as first-level-learner and meta-learner.\r\n* Use any custom model as long as they implement the `fit()`, `predict()`, and `predict_proba()` methods.\r\n* Combine different types of first-level-learners.\r\n* Comes with a pre-loaded dataset with two views for testing.\r\n\r\n## Requirements\r\n\r\n- Python 3.8+\r\n- pandas\r\n- numpy\r\n- scikit-learn >= 1.2.2\r\n\r\n## Installation\r\n\r\nYou can install the `multiviewstacking` package with:\r\n\r\n```\r\npip install multiviewstacking\r\n```\r\n\r\n## Quick start example\r\n\r\nThis quick start example shows you how to train a multi-view model. For more detailed tutorials, check the jupyter notebooks in the [/examples](https://github.com/enriquegit/multiviewstacking/tree/main/examples) directory.\r\n\r\n```python\r\nimport numpy as np\r\nfrom multiviewstacking import load_example_data\r\nfrom multiviewstacking import MultiViewStacking\r\nfrom sklearn.ensemble import RandomForestClassifier\r\n\r\n# Load the built-in example dataset.\r\n(xtrain,ytrain,xtest,ytest,ind1,ind2,l) = load_example_data()\r\n```\r\n\r\nThe built-in dataset contains features for two views (audio, accelerometer) for activity recognition.\r\nThe `load_example_data()` method returns a tuple with the train and test sets. It also returns the column indices for the two views and a LabelEnconder to convert the classes from integers back to strings.\r\n\r\n```python\r\n# Define two first-level-learners and the meta-learner.\r\n# All of them are Random Forests but they can be any other model.\r\nm_v1 = RandomForestClassifier(n_estimators=50, random_state=123)\r\nm_v2 = RandomForestClassifier(n_estimators=50, random_state=123)\r\nm_meta = RandomForestClassifier(n_estimators=50, random_state=123)\r\n\r\n# Train the model.\r\nmodel = MultiViewStacking(views_indices = [ind1, ind2],\r\n first_level_learners = [m_v1, m_v2],\r\n meta_learner = m_meta)\r\n```\r\n\r\nThe `view_indices` parameter is a list of lists. Each list specifies the column indices of the train set for each view.\r\nIn this case `ind1` stores the indices of the audio features and `ind2` contains the indices of the accelerometer features.\r\nTh `first_level_learners` parameter is a list of scikit-learn models or any other custom models. The `meta-learnr` specifies the model to be used as the meta-learner.\r\n\r\n```python\r\n# Train the model.\r\nmodel.fit(xtrain, ytrain)\r\n\r\n# Make predictions on the test set.\r\npreds = model.predict(xtest)\r\n\r\n# Compuet the accuracy.\r\nnp.sum(ytest == preds) / len(ytest)\r\n```\r\n\r\n\r\n\r\n## Citation\r\n\r\nTo cite this package use:\r\n\r\n```{r}\r\nEnrique Garcia-Ceja (2024). multiviewstacking: A python implementation of the Multi-View Stacking algorithm.\r\nPython package https://github.com/enriquegit/multiviewstacking\r\n```\r\n\r\nBibTex entry for LaTeX:\r\n\r\n```{r}\r\n@Manual{MVS,\r\n title = {multiviewstacking: A python implementation of the Multi-View Stacking algorithm},\r\n author = {Enrique Garcia-Ceja},\r\n year = {2024},\r\n note = {Python package},\r\n url = {https://github.com/enriquegit/multiviewstacking}\r\n}\r\n```\r\n\r\n\r\n## References\r\n\r\n[1] Garcia-Ceja, Enrique, et al. \"Multi-view stacking for activity recognition with sound and accelerometer data.\" Information Fusion 40 (2018): 45-56.\r\n\r\n[2] Wolpert, D. H. (1992). Stacked generalization. Neural networks, 5(2), 241-259.\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Python implementation of the Multi-View Stacking algorithm.",
"version": "0.5.0",
"project_urls": {
"Homepage": "https://github.com/enriquegit/multiviewstacking"
},
"split_keywords": [
"multi-view stacking",
" machine learning",
" classification",
" sensor fusion"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "57c5637acf3e63c49eadc5100a8a998610457005cfad8853c6e1bf2cd2b4fe6e",
"md5": "ee9fded56a9b5018eeb655a2a7730263",
"sha256": "17c7ece3de7c95b364422e949aa62538a097a202a79239b21ca848b917e9a32e"
},
"downloads": -1,
"filename": "multiviewstacking-0.5.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "ee9fded56a9b5018eeb655a2a7730263",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 423174,
"upload_time": "2025-01-28T05:34:53",
"upload_time_iso_8601": "2025-01-28T05:34:53.080155Z",
"url": "https://files.pythonhosted.org/packages/57/c5/637acf3e63c49eadc5100a8a998610457005cfad8853c6e1bf2cd2b4fe6e/multiviewstacking-0.5.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "0aa790048c9e15dfbf7f8093226d9e383c433ace82154d27ff369b61e322e059",
"md5": "1dd5a674075699a8a672eef748043c3b",
"sha256": "f51fca4e512146e3418b6e6bbfb8d07a76503a24562c8638cf55863486f64ad0"
},
"downloads": -1,
"filename": "multiviewstacking-0.5.0.tar.gz",
"has_sig": false,
"md5_digest": "1dd5a674075699a8a672eef748043c3b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 423997,
"upload_time": "2025-01-28T05:34:55",
"upload_time_iso_8601": "2025-01-28T05:34:55.220412Z",
"url": "https://files.pythonhosted.org/packages/0a/a7/90048c9e15dfbf7f8093226d9e383c433ace82154d27ff369b61e322e059/multiviewstacking-0.5.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-28 05:34:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "enriquegit",
"github_project": "multiviewstacking",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "multiviewstacking"
}