Note: This solution only applies if you consciously want to keep NaN entries in your dataset. # go through matrix one column at a time and replace + and -infinity Maxs = != np.inf]) for i in range(matrix.shape)] Mins = != -np.inf]) for i in range(matrix.shape)] # find min and max values for each column, ignoring nan, -inf, and inf Remove all infinite values: (and replace with min or max for that column) import numpy as np Now all I have to do is remove the values at these indexes. Then with a quick and dirty loop, I was able to find that my data indeed contains nans: print(p.shape) ![]() ValueError: Input contains NaN, infinity or a value too large for dtype('float64').įrom this, I was able to extract the correct way to test what was going on with my data using the same test which fails given by the error message: np.isfinite(X) ![]() > 58 " or a value too large for %r." % X.dtype) Looking at the details of the error, I found the lines of codes causing the failure: /opt/anaconda3/lib/python3.6/site-packages/sklearn/utils/validation.py in _assert_all_finite(X)ĥ7 raise ValueError("Input contains NaN, infinity" With this version of python 3: /opt/anaconda3/bin/python -version
0 Comments
Leave a Reply. |