andreSmol
andreSmol

Reputation: 1038

Scikit LDA use in RFECV

I am using the recursive feature ranking function i scikit-learn (http://scikit-learn.org/stable/modules/generated/sklearn.feature_selection.RFECV.html#sklearn.feature_selection.RFECV). However, I would like use a LDA classifier as the estimator. I have this code:

X, y = make_friedman1(n_samples=50, n_features=10, random_state=0)
estimator = LDA()
#selector = RFE(estimator,5,step = 1)
selector = RFECV(estimator, cv = 5,step = 1)
selector=selector.fit(X,y)
print selector.support_
print selector.ranking_

When I execute this code, I am getting an error. If I execute the same code with RFE, it is ok. Or if I use the SVR classifier, it works ok. My question is if I am getting a classifier when I call the method LDA().The RFECV will use the classifier in the "estimator" to rank the features. What is the problem with LDA?

Upvotes: 0

Views: 557

Answers (1)

Fred Foo
Fred Foo

Reputation: 363587

From the docs:

sklearn.datasets.make_friedman1: Generate the “Friedman #1” regression problem

(emphasis added)

You can't sensibly use a classifier on a regression problem. The reason why SVR works is that isn't a classifier learner, but a regression learner.

Upvotes: 1

Related Questions