Question: **Goal**: I aim to use t-SNE (t-distributed Stochastic Neighbor Embedding) in R for dimensionality reduction of my training data (with *N* observations and *K* variables, where *K>>N*) and subsequently aim to come up with the t-SNE representation for my test data. 

**Example**: Suppose I aim to reduce the K variables to *D=2* dimensions (often, *D=2* or *D=3* for t-SNE). There are two R packages: `Rtsne` and `tsne`, while I use the former here.

```
# load packages
library(Rtsne)

# Generate Training Data: random standard normal matrix with J=400 variables and N=100 observations
x.train <- matrix(nrom(n=40000, mean=0, sd=1), nrow=100, ncol=400)

# Generate Test Data: random standard normal vector with N=1 observation for J=400 variables
x.test <- rnorm(n=400, mean=0, sd=1)

# perform t-SNE
set.seed(1)
fit.tsne <- Rtsne(X=x.train, dims=2)

```

where the command `fit.tsne$Y` will return the (100x2)-dimensional object containing the t-SNE representation of the data; can also be plotted via `plot(fit.tsne$Y)`. 

**Problem**: Now, what I am looking for is a function that returns a prediction `pred` of dimension (1x2) for my test data based on the trained t-SNE model. Something like,

```
# The function I am looking for (but doesn't exist yet):
pred <- predict(object=fit.tsne, newdata=x.test)

```

(How) Is this possible? Can you help me out with this?

Answer: 
t-SNE does not really work this way: 

The following is an expert from the t-SNE author's website (<https://lvdmaaten.github.io/tsne/>):

> 
> Once I have a t-SNE map, how can I embed incoming test points in that
>  map?
> 
> 
> t-SNE learns a non-parametric mapping, which means that it does not
>  learn an explicit function that maps data from the input space to the
>  map. Therefore, it is not possible to embed test points in an existing
>  map (although you could re-run t-SNE on the full dataset). A potential
>  approach to deal with this would be to train a multivariate regressor
>  to predict the map location from the input data. Alternatively, you
>  could also make such a regressor minimize the t-SNE loss directly,
>  which is what I did in this paper.
> 
> 
> 

You may be interested in his paper: <https://lvdmaaten.github.io/publications/papers/AISTATS_2009.pdf>

This website in addition to being really cool offers a wealth of info about t-SNE: <http://distill.pub/2016/misread-tsne/>

On Kaggle I have also seen people do things like this which may also be of intrest:
<https://www.kaggle.com/cherzy/d/dalpozz/creditcardfraud/visualization-on-a-2d-map-with-t-sne>
t-SNE fundamentally does not do what you want. t-SNE is designed only for visualizing a dataset in a low (2 or 3) dimension space. You give it all the data you want to visualize all at once. It is not a general purpose dimensionality reduction tool. 

If you are trying to apply t-SNE to "new" data, you are probably not thinking about your problem correctly, or perhaps simply did not understand the purpose of t-SNE.