Last answered:

08 May 2020

Posted on:

05 May 2020

0

error message in python coding

Hi, I got an error message in python coding in the lesson of 'SQL + TABLUEA + PYTHON' under the section 'Training and Evaluating model" Can you give any solution. code : reg.fit(x_train,y_train) error message:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-38-ae4bf08b45bb> in <module>
----> 1 reg.fit(x_train,y_train)

~\anaconda3\lib\site-packages\sklearn\linear_model\_logistic.py in fit(self, X, y, sample_weight)
   1525 
   1526         X, y = check_X_y(X, y, accept_sparse='csr', dtype=_dtype, order="C",
-> 1527                          accept_large_sparse=solver != 'liblinear')
   1528         check_classification_targets(y)
   1529         self.classes_ = np.unique(y)

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_X_y(X, y, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, multi_output, ensure_min_samples, ensure_min_features, y_numeric, warn_on_dtype, estimator)
    753                     ensure_min_features=ensure_min_features,
    754                     warn_on_dtype=warn_on_dtype,
--> 755                     estimator=estimator)
    756     if multi_output:
    757         y = check_array(y, 'csr', force_all_finite=True, ensure_2d=False,

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
    576         if force_all_finite:
    577             _assert_all_finite(array,
--> 578                                allow_nan=force_all_finite == 'allow-nan')
    579 
    580     if ensure_min_samples > 0:

~\anaconda3\lib\site-packages\sklearn\utils\validation.py in _assert_all_finite(X, allow_nan, msg_dtype)
     58                     msg_err.format
     59                     (type_err,
---> 60                      msg_dtype if msg_dtype is not None else X.dtype)
     61             )
     62     # for object dtype data, we only check for NaNs (GH-13254)

ValueError: Input contains NaN, infinity or a value too large for dtype('float64').
2 answers ( 0 marked as helpful)
Instructor
Posted on:

07 May 2020

0
Hi Porage, It seems like your input contains values that are not numbers (probably they are strings).  Could you please display x_train and share the result here? Best,
The 365 Team
Posted on:

08 May 2020

0
hi, here it is type of x_train is " numpy.ndarray"
X_train:
array([[-0.57735027, -0.09298136, -0.31448545, ..., -0.44798003, -0.91902997, -0.58968976], [-0.57735027, -0.09298136, 3.17979734, ..., 2.23224237, 0.88046927, -0.58968976], [ 1.73205081, -0.09298136, -0.31448545, ..., 2.23224237, -0.91902997, -0.58968976], ..., [-0.57735027, -0.09298136, -0.31448545, ..., -0.44798003, -0.91902997, -0.58968976], [-0.57735027, -0.09298136, -0.31448545, ..., -0.44798003, -0.01928035, 2.8430157 ], [-0.57735027, -0.09298136, -0.31448545, ..., -0.44798003, -0.91902997, -0.58968976]])
Thanks in advanced

Submit an answer