Issue
I am able to get this to run piecemeal, but when I tried a for loop to run it across all the models I am getting an error. It looks like I am giving a list of 1 rather than the item. How do I get it to provide the item? Or is there a better way to do this?
my_list = [LogisticRegression(max_iter=1000, random_state=1),LinearDiscriminantAnalysis(), SVC(probability = True,random_state=1)]
for i in my_list:
rfecv = RFECV(estimator=[i],step=1)
rfecv.fit(x,y)
print(" ")
print(i)
for j, col, in zip(range(df.shape[1]), df.columns):
print(f'{col} selected= {rfecv.support_[1]} rank= {rfecv.ranking_[1]}')
The error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-164-f885654e3d56> in <module>
3 for i in my_list:
4 rfecv = RFECV(estimator=[i],step=1)
----> 5 rfecv.fit(x,y)
6 print(" ")
7 print(i)
1 frames
/usr/local/lib/python3.7/dist-packages/sklearn/metrics/_scorer.py in check_scoring(estimator, scoring, allow_none)
448 raise TypeError(
449 "estimator should be an estimator implementing 'fit' method, %r was passed"
--> 450 % estimator
451 )
452 if isinstance(scoring, str):
TypeError: estimator should be an estimator implementing 'fit' method, [LogisticRegression(max_iter=1000, random_state=1)] was passed
Solution
You are putting i
in a list, so instead of passing [i]
to the fit
function just pass i
:
my_list = [LogisticRegression(max_iter=1000, random_state=1),LinearDiscriminantAnalysis(), SVC(probability = True,random_state=1)]
for i in my_list:
rfecv = RFECV(estimator=i,step=1)
rfecv.fit(x,y)
print(" ")
print(i)
for j, col, in zip(range(df.shape[1]), df.columns):
print(f'{col} selected= {rfecv.support_[1]} rank= {rfecv.ranking_[1]}')
Answered By - Adam Jaamour
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.