unable to use sequential feature selection

104 views
Skip to first unread message

Alok Gogate

unread,
May 4, 2018, 7:14:43 AM5/4/18
to mlxtend
Hello I am unable to use this method as I am getting the below error continuously:


TypeError: unhashable type: 'slice'


this is my code:
knn = KNeighborsClassifier(n_neighbors=5,n_jobs=-1)
sfs = SFS(knn,
         k_features=16,
         forward=True,
         floating=False,
         scoring='accuracy',
         cv=2)
sfs.fit(x,y)

my x has 16 feature columns and y is a 1/0 class 

Any suggestions as to what may be causing this?

Thanks!

Roy Wright

unread,
May 4, 2018, 11:05:41 AM5/4/18
to mlxtend
Looks like x and y are pandas dataframes.

Change your last line to:
sfs.fit(x.values, y.values)

Sebastian Raschka

unread,
May 5, 2018, 8:39:04 AM5/5/18
to mlxtend
Hi Alok,

Roy is right, the error is likely due to passing DataFrames instead of a NumPy(-like) array to the estimator. I recently started to add support for pandas DataFrames though -- I will try to get back to it this weekend or so and make those compatible.

Best,
Sebastian
> --
> You received this message because you are subscribed to the Google Groups "mlxtend" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mlxtend+u...@googlegroups.com.
> To post to this group, send email to mlx...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/mlxtend/9317fbb9-b411-4036-890a-e0686afd8722%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Alok Gogate

unread,
May 5, 2018, 9:39:13 AM5/5/18
to Sebastian Raschka, mlxtend
Thanks Sebastian, I've followed Roy's tip and was able to proceed further. This is a very useful library for me. Looking forward to using this with data frame support
Thanks
Alok

Sent from my iPhone
> To view this discussion on the web visit https://groups.google.com/d/msgid/mlxtend/CD509A9A-732B-4E32-BD9E-80520068ADB2%40gmail.com.

Sebastian Raschka

unread,
Jun 22, 2018, 5:52:07 PM6/22/18
to Alok Gogate, mlxtend
I am currently cleaning out my email inbox and noticed that I forgot to follow up on this. I implemented the DataFrame support back in May (https://github.com/rasbt/mlxtend/pull/379), and you can use it from the master branch now (I want to accumulate a few more features before making a new release version). To install the current development version from the master branch, you can use the command: pip install git+git://github.com/rasbt/mlxtend.git

Best,
Sebastian

Alok Gogate

unread,
Jun 23, 2018, 3:44:01 AM6/23/18
to Sebastian Raschka, mlxtend
Thanks Sebastian, I will check this from the master branch.
Looking forward to see more features and do let me know in what way I can help in gathering more features

Thanks
Alok

Sent from my iPhone

Sebastian Raschka

unread,
Jun 23, 2018, 9:36:23 PM6/23/18
to Alok Gogate, mlxtend
Hi, Alok,

Thanks for offering your help with regard to adding features. Of course, there are always more things one could add to the issue tracker, but looking at the items that are already on there, maybe working on these would probably be better than adding more at the moment. So, if you ever feel like it, I would appreciate a PR :).

Best,
Sebastian
Reply all
Reply to author
Forward
0 new messages