File: test_sklearn_wrapper.py

package info (click to toggle)
opentsne 1.0.2-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 26,328 kB
  • sloc: python: 4,721; cpp: 1,959; makefile: 20
file content (34 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import unittest
import numpy as np

from openTSNE.sklearn import TSNE


class TestTSNECorrectness(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        cls.tsne = TSNE(
            early_exaggeration_iter=20,
            n_iter=100,
            neighbors="exact",
            negative_gradient_method="bh",
        )
        # Set up two modalities, if we want to viually inspect test results
        random_state = np.random.RandomState(0)
        cls.x = np.vstack(
            (random_state.normal(+1, 1, (100, 4)), random_state.normal(-1, 1, (100, 4)))
        )
        cls.x_test = random_state.normal(0, 1, (25, 4))

    def test_fit(self):
        retval = self.tsne.fit(self.x)
        self.assertIs(type(retval), TSNE)

    def test_fit_transform(self):
        retval = self.tsne.fit_transform(self.x)
        self.assertIs(type(retval), np.ndarray)

    def test_transform(self):
        self.tsne.fit(self.x)
        retval = self.tsne.transform(self.x_test)
        self.assertIs(type(retval), np.ndarray)