Thanks to visit codestin.com
Credit goes to github.com

Skip to content

GaussianNB().fit(_,_,sample_weights) , sample_weights only takes lists #8329

@gsubramani

Description

@gsubramani

Description

When using GaussianNB with weights to fit, it only accepts numpy arrays and not generic python lists which is contrary to other algoithms in sklearn
Related bug/feature request: #4346

Steps/Code to Reproduce

from sklearn.naive_bayes import GaussianNB
import numpy as np
gnb = GaussianNB()

# gnb.fit([[1,2],[2,2],[1,1]],[1,2,1],[1,1,1]) # causes error here
'''
ERROR:
Traceback (most recent call last):
  File "testGNBWeights.py", line 5, in <module>
    gnb.fit([[1,2],[2,2],[1,1]],[1,2,1],[1,1,1]) # causes error here
  File "/usr/local/lib/python2.7/dist-packages/sklearn/naive_bayes.py", line 184, in fit
    sample_weight=sample_weight)
  File "/usr/local/lib/python2.7/dist-packages/sklearn/naive_bayes.py", line 398, in _partial_fit
    sw_i = sample_weight[y == y_i]
'''

gnb.fit([[1,2],[2,2],[1,1]],[1,2,1],np.array([1,1,1])) # this works!


Expected Results

NA

Actual Results

Error

Versions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions