ValueError: Found array with 0 sample(s) (shape=(0, 0)) while a minimum of 2 is required by TSNE

Viewed 165

I have this piece of code that I'm using in my doc2vec model

distance_matrix_doc = pairwise_distances(X_doc_subset, X_doc_subset, metric='cosine', n_jobs=-1)

tsne_doc = TSNE(metric="precomputed", n_components=2, verbose=1, perplexity=30, n_iter=500)

tsne_results_doc = tsne_doc.fit_transform(distance_matrix_doc)

after running it I am getting the following error:

ValueError: Found array with 0 sample(s) (shape=(0, 0)) while a minimum of 2 is required by TSNE.

What might be the problem and how do I correct it?

1 Answers

Getting that error suggests that your distance_matrix_doc is empty: it's got "0 samples", and "shape(0,0)". Which also implies that your X_doc_subset is empty. Of course, these steps can't do anything without input data.

So, look back at the prior code that was suppposed-to fill X_doc_subset, and check at each step, by observing the interim results, that it's doing what you intended before proceeding to these steps.

Related