Package to visualise component-based decomposition models such as PCA and PARAFAC
Project description
TLViz is a Python package for visualising component-based decomposition models like PARAFAC and PCA.
Documentation
The documentation is available on the TensorLy website and includes
Dependencies
TLViz supports Python 3.8 or above (it may also work with Python 3.6 and 3.7, though that is not officially supported).
Installation requires matplotlib, numpy, pandas, scipy, statsmodels and xarray.
Installation
To install the latest stable release of TLViz and its dependencies, run:
pip install tensorly-viz
There is also functionality to create improved QQ-plots with Pingoiun. However, this is disabled by default due to the restrictive GPL lisence. To enable this possibility, you must manually install Pingoiun.
To install the latest development version of TLViz, you can either clone this repo or run
pip install git+https://github.com/marieroald/tlviz.git
Some extra dependencies are needed to run the examples, tests or build the documentation. For more information about installing these dependencies, see the installation guide.
Example
import tlviz
import matplotlib.pyplot as plt
from tensorly.decomposition import parafac
def fit_parafac(dataset, num_components, num_inits):
model_candidates = [
parafac(dataset.data, num_components, init="random", random_state=i)
for i in range(num_inits)
]
model = tlviz.multimodel_evaluation.get_model_with_lowest_error(
model_candidates, dataset
)
return tlviz.postprocessing.postprocess(model, dataset)
data = tlviz.data.load_aminoacids()
cp_tensor = fit_parafac(data, 3, num_inits=3)
tlviz.visualisation.components_plot(cp_tensor)
plt.show()
Loading Aminoacids dataset from:
Bro, R, PARAFAC: Tutorial and applications, Chemometrics and Intelligent Laboratory Systems, 1997, 38, 149-171
This example uses TensorLy to fit five three-component PARAFAC models to the data. Then it uses TLViz to do the following steps:
Select the model that gave the lowest reconstruction error.
Normalise the component vectors, storing their magnitude in a separate weight-vector.
Permute the components in descending weight (i.e. signal strength) order.
Flip the components so they point in a logical direction compared to the data.
Convert the factor matrices into Pandas DataFrames with logical indices.
Plot the components using matplotlib.
All these steps are described in the API documentation with references to the literature.
Testing
The test suite requires an additional set of dependencies. To install these, run
pip install tlviz[test]
or
pip install -e .[test]
inside your local copy of the TLViz repository.
The tests can be run by calling pytest with no additional arguments. All doctests are ran by default and a coverage summary will be printed on the screen. To generate a coverage report, run coverage html.
Contributing
Contributions are welcome to TLViz, see the contribution guidelines.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tensorly-viz-0.1.7.tar.gz
.
File metadata
- Download URL: tensorly-viz-0.1.7.tar.gz
- Upload date:
- Size: 633.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 43c9bd02b6ea5fa33ffc78a54b5f3a934dff2406ac8a3727ed0d48eea5681440 |
|
MD5 | 8f1f6496d0d97cedf7a187aaea520491 |
|
BLAKE2b-256 | 345f3fbf40d70f417b63120b153e15048b238862b754aa317df8ac19360223e0 |
File details
Details for the file tensorly_viz-0.1.7-py2.py3-none-any.whl
.
File metadata
- Download URL: tensorly_viz-0.1.7-py2.py3-none-any.whl
- Upload date:
- Size: 702.0 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.16
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5036c64dd8d561f148c6ebe26ad5edd4cfc4e00aa84f9703505de7a28bc70d59 |
|
MD5 | efef4c7a0838fa30dc87b73cfaf517f1 |
|
BLAKE2b-256 | d089c7712a15477a0b7577603036c7a4a23ca7dcff75b56f598dcded6c444bda |