Uncategorized

python – How do I solve a Value Error in Machine Learning?


I’m trying to select and train my model using Naive Bayes and I’m dealing with a Dataset of Diabetics but I keep getting a Value Error like this:

ValueError                                Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_15552\3536100043.py in ?()
      1 model = GaussianNB()
----> 2 model.fit(X_train, y_train)

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\naive_bayes.py in ?(self, X, y, sample_weight)
    263             Returns the instance itself.
    264         """
    265         self._validate_params()
    266         y = self._validate_data(y=y)
--> 267         return self._partial_fit(
    268             X, y, np.unique(y), _refit=True, sample_weight=sample_weight
    269         )

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\naive_bayes.py in ?(self, X, y, classes, _refit, sample_weight)
    424         if _refit:
    425             self.classes_ = None
    426 
    427         first_call = _check_partial_fit_first_call(self, classes)
--> 428         X, y = self._validate_data(X, y, reset=first_call)
    429         if sample_weight is not None:
    430             sample_weight = _check_sample_weight(sample_weight, X)
    431 

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\base.py in ?(self, X, y, reset, validate_separately, **check_params)
    580                 if "estimator" not in check_y_params:
    581                     check_y_params = {**default_check_params, **check_y_params}
    582                 y = check_array(y, input_name="y", **check_y_params)
    583             else:
--> 584                 X, y = check_X_y(X, y, **check_params)
    585             out = X, y
    586 
    587         if not no_val_X and check_params.get("ensure_2d", True):

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\utils\validation.py in ?(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, estimator)
   1102         raise ValueError(
   1103             f"{estimator_name} requires y to be passed, but the target y is None"
   1104         )
   1105 
-> 1106     X = check_array(
   1107         X,
   1108         accept_sparse=accept_sparse,
   1109         accept_large_sparse=accept_large_sparse,

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\utils\validation.py in ?(array, accept_sparse, accept_large_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, estimator, input_name)
    876                         )
    877                     array = xp.astype(array, dtype, copy=False)
    878                 else:
    879                     array = _asarray_with_order(array, order=order, dtype=dtype, xp=xp)
--> 880             except ComplexWarning as complex_warning:
    881                 raise ValueError(
    882                     "Complex data not supported\n{}\n".format(array)
    883                 ) from complex_warning

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\sklearn\utils\_array_api.py in ?(array, dtype, order, copy, xp)
    181     if xp is None:
    182         xp, _ = get_namespace(array)
    183     if xp.__name__ in {"numpy", "numpy.array_api"}:
    184         # Use NumPy API to support order
--> 185         array = numpy.asarray(array, order=order, dtype=dtype)
    186         return xp.asarray(array, copy=copy)
    187     else:
    188         return xp.asarray(array, dtype=dtype, copy=copy)

~\AppData\Local\Programs\Python\Python311\Lib\site-packages\pandas\core\generic.py in ?(self, dtype)
   1996     def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
   1997         values = self._values
-> 1998         arr = np.asarray(values, dtype=dtype)
   1999         if (
   2000             astype_is_view(values.dtype, arr.dtype)
   2001             and using_copy_on_write()

ValueError: could not convert string to float: 'F'

I tried running all the cells of code again because I am using Jupyter Notebook but it’s the same result I keep getting.



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *