[med-svn] [Git][med-team/umap-learn][master] Add example code and install it

Nilesh Patra gitlab at salsa.debian.org
Tue May 26 18:53:40 BST 2020



Nilesh Patra pushed to branch master at Debian Med / umap-learn


Commits:
88d778af by Nilesh Patra at 2020-05-26T23:22:28+05:30
Add example code and install it

- - - - -


2 changed files:

- + debian/Example/umap_example.py
- + debian/examples


Changes:

=====================================
debian/Example/umap_example.py
=====================================
@@ -0,0 +1,69 @@
+import matplotlib.pyplot as plt
+import numba
+import numpy as np
+from sklearn.datasets import load_digits, make_classification
+from sklearn.model_selection import train_test_split, GridSearchCV
+from sklearn.svm import LinearSVC
+from sklearn.pipeline import Pipeline
+from umap import *
+
+print('import done')
+
+digits = load_digits()
+X_train, X_test, y_train, y_test = train_test_split(
+    digits.data, digits.target, stratify=digits.target, random_state=1000
+)
+
+trans = UMAP(
+        n_neighbors=5,
+        random_state=42,
+        metric="manhattan",
+        output_metric="manhattan",
+        verbose=True,
+).fit(X_train)
+
+plt.scatter(trans.embedding_[:, 0], trans.embedding_[:, 1], c=y_train, cmap="Spectral")
+plt.savefig('foo.png')
+
+x, y = make_classification(
+    n_samples=1000,
+    n_features=300,
+    n_informative=250,
+    n_redundant=0,
+    n_repeated=0,
+    n_classes=2,
+    random_state=1212,
+)
+
+print('Splitting into training and testing data ...')
+X_train, X_test, y_train, y_test = train_test_split(
+    x, y, test_size=0.2, random_state=42
+)
+
+print('Run linear SVM algorithm')
+svc = LinearSVC(dual=False, random_state=123)
+params_grid = {"C": [10 ** k for k in range(-3, 4)]}
+clf = GridSearchCV(svc, params_grid)
+clf.fit(X_train, y_train)
+print(
+    "Accuracy on the test set with raw data: {:.3f}".format(clf.score(X_test, y_test))
+)
+
+print('Transform with UMAP, then run SVM')
+umap = UMAP(random_state=456)
+pipeline = Pipeline([("umap", umap), ("svc", svc)])
+params_grid_pipeline = {
+    "umap__n_neighbors": [5, 20],
+    "umap__n_components": [15, 25, 50],
+    "svc__C": [10 ** k for k in range(-3, 4)],
+}
+
+
+clf_pipeline = GridSearchCV(pipeline, params_grid_pipeline)
+clf_pipeline.fit(X_train, y_train)
+print(
+    "Accuracy on the test set with UMAP transformation: {:.3f}".format(
+        clf_pipeline.score(X_test, y_test)
+    )
+)
+


=====================================
debian/examples
=====================================
@@ -0,0 +1 @@
+debian/Example/*



View it on GitLab: https://salsa.debian.org/med-team/umap-learn/-/commit/88d778af844b2a3f447b318b68c7ae34070b71c7

-- 
View it on GitLab: https://salsa.debian.org/med-team/umap-learn/-/commit/88d778af844b2a3f447b318b68c7ae34070b71c7
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://alioth-lists.debian.net/pipermail/debian-med-commit/attachments/20200526/6aef1a24/attachment-0001.html>


More information about the debian-med-commit mailing list