For the sample_weight, the requirement of its shape is array-like shape (n_samples,), sometimes is array-like shape [n_samples]. Does (n_samples,) means 1d array? and [n_samples] means list? Or they're equivalent to each other? Both forms can be seen here:

2

1 Answer

You can use a simple example to test this:

import numpy as np from sklearn.naive_bayes import GaussianNB #create some data X = np.array([[-1, -1], [-2, -1], [-3, -2], [1, 1], [2, 1], [3, 2]]) Y = np.array([1, 1, 1, 2, 2, 2]) #create the model and fit it clf = GaussianNB() clf.fit(X, Y) #check the type of some attributes type(clf.class_prior_) type(clf.class_count_) #check the shapes of these attributes clf.class_prior_.shape clf.class_count_ 

Or more advanced searching:

#verify that it is a numpy nd array and NOT a list isinstance(clf.class_prior_, np.ndarray) isinstance(clf.class_prior_, list) 

Similarly, you can check all the attributes.

Results

numpy.ndarray numpy.ndarray (2,) array([ 3., 3.]) True False 

The results indicate that these atributes are numpy nd arrays.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy