Wertfehler: String kann nicht in Float konvertiert werdenPython

Python-Programme
Anonymous
 Wertfehler: String kann nicht in Float konvertiert werden

Post by Anonymous »

Code: Select all

from sklearn.preprocessing import OneHotEncoder
enc=OneHotEncoder(handle_unknown='ignore')
X=[['gender', 1], ['NationalITy', 2], ['PlaceofBirth', 3],['StageID', 4], ['GradeID', 5], ['SectionID', 6],['Topic', 7], ['Semester', 8], ['Relation', 9],['raisedhands', 1], ['VisITedResources', 2], ['AnnouncementsView', 3],['Discussion', 4], ['ParentAnsweringSurvey', 5], ['ParentschoolSatisfaction', 6],['Class',7]]
enc.fit_transform(X)
Ich bekomme

Code: Select all

ValueError                                Traceback (most recent call last)  in ()
----> 1 enc.fit_transform(X)

~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in fit_transform(self, X, y)    2017         """    2018         return
_transform_selected(X, self._fit_transform,
-> 2019                                    self.categorical_features, copy=True)    2020     2021     def _transform(self, X):

~\Anaconda3\lib\site-packages\sklearn\preprocessing\data.py in
_transform_selected(X, transform, selected, copy)    1807     X : array or sparse matrix, shape=(n_samples, n_features_new)    1808     """
-> 1809     X = check_array(X, accept_sparse='csc', copy=copy, dtype=FLOAT_DTYPES)    1810     1811     if isinstance(selected, six.string_types) and selected == "all":

~\Anaconda3\lib\site-packages\sklearn\utils\validation.py in check_array(array, accept_sparse, dtype, order, copy, force_all_finite, ensure_2d, allow_nd, ensure_min_samples, ensure_min_features, warn_on_dtype, estimator)
431                                       force_all_finite)
432     else:
--> 433         array = np.array(array, dtype=dtype, order=order, copy=copy)
434
435         if ensure_2d:

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

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post