Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
rfecv_4_rfecv
X = data.drop('Survived', axis=1)
target = data['Survived']
rfc = RandomForestClassifier(random_state=101)
rfecv = RFECV(estimator=rfc, step=1, cv=StratifiedKFold(10), scoring='accuracy')
rfecv.fit(X, target)
@docsuhail

This comment has been minimized.

Copy link

@docsuhail docsuhail commented Nov 27, 2020

Can you please check this code

@docsuhail

This comment has been minimized.

Copy link

@docsuhail docsuhail commented Nov 27, 2020

ValueError Traceback (most recent call last)
in
4 rfc = RandomForestClassifier(random_state=101)
5 rfecv = RFECV(estimator=rfc, step=1, cv=StratifiedKFold(10), scoring='accuracy')
----> 6 rfecv.fit(X, target)

~/opt/anaconda3/lib/python3.7/site-packages/sklearn/feature_selection/_rfe.py in fit(self, X, y, groups)
491 """
492 X, y = check_X_y(X, y, "csr", ensure_min_features=2,
--> 493 force_all_finite=False)
494
495 # Initialization

~/opt/anaconda3/lib/python3.7/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,

~/opt/anaconda3/lib/python3.7/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)
529 array = array.astype(dtype, casting="unsafe", copy=False)
530 else:
--> 531 array = np.asarray(array, order=order, dtype=dtype)
532 except ComplexWarning:
533 raise ValueError("Complex data not supported\n"

~/opt/anaconda3/lib/python3.7/site-packages/numpy/core/_asarray.py in asarray(a, dtype, order)
83
84 """
---> 85 return array(a, dtype, copy=False, order=order)
86
87

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment