n_iter should be at least 250
Package:
scikit-learn
47032

Exception Class:
ValueError
Raise code
random_state = check_random_state(self.random_state)
if self.early_exaggeration < 1.0:
raise ValueError("early_exaggeration must be at least 1, but is {}"
.format(self.early_exaggeration))
if self.n_iter < 250:
raise ValueError("n_iter should be at least 250")
n_samples = X.shape[0]
neighbors_nn = None
if self.method == "exact":
# Retrieve the distance matrix, either using the precomputed one or
# computing it.
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too!
We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.
Links to the raise (1)
https://github.com/scikit-learn/scikit-learn/blob/c67518350f91072f9d37ed09c5ef7edf555b6cf6/sklearn/manifold/_t_sne.py#L775Ways to fix
Summary:
This exception can be thrown when creating an instance of TSNE and calling the _fit function. The init function for this class includes lots of optional parameters. The parameter that can lead to this exception is n_iter. This parameter expects an integer to be passed into it, and that integer must be greater than or equal to 250. Any value passed in that is less than 250, will cause this exception.
Code to Reproduce the Error (Wrong):
from sklearn.manifold._t_sne import TSNE
import numpy as np
x = np.array([[1, 2], [3, 4]])
iterations = 100
t = TSNE(n_iter=iterations)
t._fit(x)
Error Message:
ValueError Traceback (most recent call last)
<ipython-input-8-bb93ce2402e2> in <module>()
5 iterations = 100
6 t = TSNE(n_iter=iterations)
----> 7 t._fit(x)
/usr/local/lib/python3.7/dist-packages/sklearn/manifold/_t_sne.py in _fit(self, X, skip_num_points)
695
696 if self.n_iter < 250:
--> 697 raise ValueError("n_iter should be at least 250")
698
699 n_samples = X.shape[0]
ValueError: n_iter should be at least 250
Working Version (Right):
from sklearn.manifold._t_sne import TSNE
import numpy as np
x = np.array([[1, 2], [3, 4]])
iterations = 300
t = TSNE(n_iter=iterations)
t._fit(x)
Successful Output:
array([[ 2901.4639, 1243.7153], [-2901.4639, -1243.7153]], dtype=float32)
Add a possible fix
Please authorize to post fix