-
-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8a1f66c
commit f4da97c
Showing
1 changed file
with
36 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
``` | ||
|