Skip to main content

Saturn coefficient to assess the results of an UMAP dimensionality reduction

Project description

Saturn score

Article

More information about this package can be found in the following article:

Davide Chicco, Simone Melzi, Francesca Gasparini and Giuseppe Jurman, "The advantages of our proposed Saturn coefficient over continuity and trustworthiness for UMAP dimensionality reduction evaluation", PeerJ Computer Science 12:e3424. https://doi.org/10.7717/peerj-cs.3424

Summary

A Python package that computes the Saturn coefficient of a matrix to assess the quality of its UMAP dimensionality reduction.

Please notice that I developed the Saturn coefficient package originally in R, which is programming language I know better and is also where I was able to make more tests. I then ported this software package from R to Python, and here you can find the outcome. If you find anything that should be improved, please let me know.

Installation and example execution

You can run the following Python code to test your package installation. It will first install the needed packages and then apply the Saturn coefficient calculation:

import subprocess
import sys

bash_command = sys.executable +" -m pip install --upgrade pip"
# Execute the bash command
print("bash_command:\n", bash_command)
result = subprocess.run(bash_command, shell=True, capture_output=True, text=True)

# List of libraries to check/install
libraries = ["numpy", "pandas", "scipy", "umap-learn", "scikit-learn", "saturnscore"]

for lib in libraries:
    try:
        __import__(lib)
        print(f"{lib} is already installed.")
    except ImportError:
        print(f"{lib} not found. Installing...")
        subprocess.check_call([sys.executable, "-m", "pip", "install", lib])

# Print the output and errors (if any)
print("output:\t", result.stdout)
error = result.stderr
if(error):
    print("errors:\t", error)

import numpy as np
import pandas as pd
import scipy
import umap.umap_ as umap
from saturnscore import Saturn_coefficient
from sklearn.preprocessing import StandardScaler

base = 120
height = 200
this_random_seed = 0
np.random.seed(this_random_seed)  # Set random seed for reproducibility

these_n_neighbors = 20
this_min_dist = 0.01
these_n_components = 2
this_metric = 'euclidean'
this_random_state = 42
this_n_jobs = 1
this_n_epochs = 200

print("these_n_neighbors = ", these_n_neighbors)
print("this_min_dist = ", this_min_dist)
print("these_n_components = ", these_n_components)
print("this_metric = ", this_metric)

umap_verbose = False
fit = umap.UMAP(n_neighbors=these_n_neighbors,
min_dist=this_min_dist,
n_components=these_n_components,
metric=this_metric,
n_jobs=this_n_jobs,
random_state=this_random_state,
n_epochs = this_n_epochs,
verbose=umap_verbose)

umap_output_layout = fit.fit_transform(input_data)

result = Saturn_coefficient.SaturnCoefficient(input_data, umap_output_layout)
print(f"Saturn coefficient =  ", result, " in the [0, 1] interval (the higher, the better)")

The final command should print something like Saturn coefficient = 0.1029461972317906 (this value might be slightly different because of the random component of UMAP).

Contact

The SaturnScore package was developed by Davide Chicco. Questions should be addressed to davidechicco(AT)davidechicco.it

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

saturnscore-1.2.2.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

saturnscore-1.2.2-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file saturnscore-1.2.2.tar.gz.

File metadata

  • Download URL: saturnscore-1.2.2.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for saturnscore-1.2.2.tar.gz
Algorithm Hash digest
SHA256 98ebe8565230ed402715a2ab17c87eb1e891838549ba2d713e88a03e78a27855
MD5 91dea89875a48ae203742dc568065a0d
BLAKE2b-256 20ee29a3965f345ac456d4530349bb91d946c5606aadadf2ec870f62236b0e79

See more details on using hashes here.

File details

Details for the file saturnscore-1.2.2-py3-none-any.whl.

File metadata

  • Download URL: saturnscore-1.2.2-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.9

File hashes

Hashes for saturnscore-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 38f6d5c3c4b3c193b21ceaff97ccc685bffee4d96d8b93e155f4a14c29e967c9
MD5 0e7b4e6176340a60a68e806a4a2e88fa
BLAKE2b-256 4c3416f1f5367ffa31b194dcc5b61cd07c93b6c9301862653309fea52010b5cf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page