0

How do you fix inconsistent numbers of samples when using GaussianNB()? Also, is it possible for input pandas dataframe as arguments for model.fit function?

enter image description here enter image description here

Sergei Lebedev
  • 2,659
  • 20
  • 23
MLhacker
  • 1,382
  • 4
  • 20
  • 35

1 Answers1

2

The issue is that GaussianNB is expecting weather to be in the shape (n_samples, n_features). You currently have it as a one-dimensional array, so GaussianNB is interpreting it as a 1 sample with 14 features.

To convert to the right shape, you can use weather[:,None] as described in this answer. So, the following should do the trick:

model.fit(weather[:,None], play)
Community
  • 1
  • 1
root
  • 32,715
  • 6
  • 74
  • 87
  • No problem. Also, looking at your code, note that you can just do `play = df_numeric.play.values` to get a numpy array from a dataframe column. – root Mar 11 '16 at 19:34