Skip to content

Commit

Permalink
TSNe embedding example #1904
Browse files Browse the repository at this point in the history
  • Loading branch information
nonunicorn committed Dec 16, 2022
1 parent 8a1f66c commit f4da97c
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions python-scikit-learn/tsne-embedding-example.md
Original file line number Diff line number Diff line change
@@ -0,0 1,36 @@
# TSNe embedding example

```python
import numpy as np
from sklearn import manifold

X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
Xe = manifold.TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(X)
```

- `import numpy` - import [lib:Numpy](https://onelinerhub.com/python-numpy/how-to-install-python-numpy-lib) module
- `from sklearn import` - import module from [lib:scikit-learn](https://onelinerhub.com/python-scikit-learn/how-to-install-scikit-learn-using-pip)
- `.TSNE(` - creates T-distributed Stochastic Neighbor Embedding model
- `n_components=2` - reduce dataset to 2 features
- `.fit_transform(` - train and transform given dataset
- `Xe` - will contain embedded dataset

group: tsne

## Example:
```python
import numpy as np
from sklearn.manifold import TSNE

X = np.array([[0, 0, 0], [0, 1, 1], [1, 0, 1], [1, 1, 1]])
print(X.shape)

Xe = TSNE(n_components=2, learning_rate='auto', init='random').fit_transform(X)
print(Xe.shape)
```
```
(4, 3)
(4, 2)
```

0 comments on commit f4da97c

Please sign in to comment.