spartans - SPARse Tools for ANalysiS
When working with sparse matrices, it is desired to have a way to work with them as if they were a regular numpy.arrays. Yet, many popular methods for arrays don’t exist for sparse matrices. spartans wishes to help, with many operations to work with
Full example notebook
Free software: GNU General Public License v3
Documentation: https://spartans.readthedocs.io.
Features
- Mathematical Operations
Rich set of operations not supported on sparse matrices like variance, cov (covariance matrix) and corrcoef (correlation matrix).
- Easy Indexing
Convenient methods to index for “extra” sparse features by variance or by quantity.
- Masking
Many algorithms consider the zeros in a sparse matrix as missing data. Or considering missing data as zeros. Depending on the use-case. spartans
- FeatureMatrix
FeatureMatrix is a spartan's first-class citizen. It is a wrapper around scipy.sparse.csr Matrix built with data analysis and data-science in mind.
Examples
Full example notebook
>>> import spartans as st
>>> from scipy.sparse import csr_matrix
>>> import numpy as np
>>> m = np.array([[1, -2, 0, 50],
[0, 0, 0, 100],
[1, 0, 0, 80],
[1, 4, 0, 0],f
[0, 0, 0, 0],
[0, 4, 0, 0],
[0, 0, 0, -50]])
>>> c = csr_matrix(m)
We can get the the correlation matrix of m using numpy.
>>> np.corrcoef(m, rowvar=False)
Out[]: array([[ 1. , -0.08, nan, 0.31],
[-0.08, 1. , nan, -0.35],
[ nan, nan, nan, nan],
[ 0.31, -0.35, nan, 1. ]])
This won’t work with the sparse matrix c
>>> np.corrcoef(c, rowvar=False)
AttributeError: 'float' object has no attribute 'shape'
But with spartans this can be done.
>>> st.corr(c)
Out[]: array([[ 1. , -0.08, nan, 0.31],
[-0.08, 1. , nan, -0.35],
[ nan, nan, nan, nan],
[ 0.31, -0.35, nan, 1. ]])
The column and row with nan is because the original matrix has a columns (feature) which is zero for the entire column. spartans can handle that using st.non_zero_index(c, axis=0, as_bool=False) which will return array([0, 1, 3]). A lot more functionality is in the notebook.
Credits
This open-source project is backed by SentinelOne
This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.
History
0.1.0 (2020-02-20)
First release on PyPI.
Metadata
Release files for spartans 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| spartans-0.2.0.tar.gz | 25.9 kB | Without provenance | Details for spartans-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| spartans-0.2.0-py2.py3-none-any.whl | Python 3, Python 2 | none | any | Details for spartans-0.2.0-py2.py3-none-any.whl |
Total release size: 44.6 kB
Release files / spartans-0.2.0.tar.gz
| Download URL | spartans-0.2.0.tar.gz |
|---|---|
| Size | 25.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8358421f26b9e120d5785d9359902dc277e258a9b50396de1a457ed8d1899798
|
|
BLAKE2b-256 checksum How to use checksums |
ed0a417fa3deb89ce3b5e9e4f7b48cf56a42d29957043609de392a60f5f7c15d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
|
Release files / spartans-0.2.0-py2.py3-none-any.whl
| Download URL | spartans-0.2.0-py2.py3-none-any.whl |
|---|---|
| Size | 18.7 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
cbd16b167d0b5d51cdf4d9ee569b631677cbcb4a47d50dad7692a3594e939810
|
|
BLAKE2b-256 checksum How to use checksums |
f755f1a641e37c872e74a3b244500670c74b6ff530c92ab12b9de104569b6942
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.5
|
Security for spartans 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.