Skip to content

Instantly share code, notes, and snippets.

@dradecic
Created September 1, 2019 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dradecic/ce30af3efc6072f18e67f0d54a13f8e7 to your computer and use it in GitHub Desktop.
Save dradecic/ce30af3efc6072f18e67f0d54a13f8e7 to your computer and use it in GitHub Desktop.
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
Copy link

Can you please check this code

@docsuhail
Copy link

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