+ 2

How to fix array shape sklearn

I'm trying to understand KFolds. I have an issue, I had a huge key error that made no sense, I changed the n_splits to 5, but it throws another error. This time the n_splits can't be used when n_samples is 4. I try to change the n_samples but it throws more errors. I can't win. Have any number other than 5 and it throws a key error, have it 5 and it throws another error! https://code.sololearn.com/cukr310h92oh/?ref=app Steven M Sorry for asking again EDIT: Bug fixed, but now I have bad input shape! 😒

20th Jul 2020, 12:15 PM
Clueless Coder
Clueless Coder - avatar
8 Réponses
+ 2
Steven M Thank you for the answer. I don't really understand how to implement this. I don't know what any of this means. It seems whenever try to make a simple program, I get lead down a million rabbit holes. I tried my best to implement it, but it made twice as many errors. https://code.sololearn.com/cukr310h92oh/?ref=app
20th Jul 2020, 3:58 PM
Clueless Coder
Clueless Coder - avatar
+ 1
Clueless Coder I wrote a quick example with the various validation functions using the cancer dataset that is built into Sci-kit Learn. You can call the KFolds in the cross_val_score function. Also, you can set your predictions calling the cross_val_predict function with your features and targets. I hope this helps. 👍👍 https://code.sololearn.com/cHHQ2iGB72ai/?ref=app
20th Jul 2020, 3:38 PM
Steven M
Steven M - avatar
+ 1
Clueless Coder I see the problem, your dataset is too small and when you apply the label encoder it does not meet the class requirements. To fix this, I expanded your dataset with 2 extra unique values. Weird things like this happen with small datasets. The code below generates a warning, but it executes without errors. https://code.sololearn.com/cvIyMA3dfb95/?ref=app
20th Jul 2020, 6:00 PM
Steven M
Steven M - avatar
+ 1
Steven M Thanks so much! They don't tell you this stuff when learning lol.
20th Jul 2020, 6:03 PM
Clueless Coder
Clueless Coder - avatar
+ 1
Sorry, try it again, I was still playing with it
20th Jul 2020, 6:09 PM
Steven M
Steven M - avatar
+ 1
Clueless Coder no worries, it's all good, I would recommend getting a csv of a couple hundred rows, at least and start playing with that data, the more data, the better these models will work
20th Jul 2020, 6:12 PM
Steven M
Steven M - avatar
+ 1
Steven M Thanks. I think it's working now. It throws 10 warnings (once again, it thinks the n_split is 3, despite making it 6). I don't like Sklearn 😂. The errors make no sense and always contradict each other. Change the input shape error, you do as it asks, and it throws more errors.
20th Jul 2020, 6:15 PM
Clueless Coder
Clueless Coder - avatar
0
Steven M Still errors 😒. I set it as n_splits=6, but it still thinks it's n_splits=5.
20th Jul 2020, 6:08 PM
Clueless Coder
Clueless Coder - avatar