首页 文章

sklearn文档中类似于数组的形状(n_samples,)vs [n_samples]

提问于
浏览
2

对于sample_weight,其形状的要求是类似于数组的形状(n_samples),有时是类似于数组的形状[n_samples] . (n_samples,)是指1d数组吗?和[n_samples]表示列表?或者他们彼此相同?这两种形式都可以在这里看到:http://scikit-learn.org/stable/modules/generated/sklearn.naive_bayes.GaussianNB.html

1 回答

  • 0

    您可以使用一个简单的示例来测试它:

    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)
    

    同样,您可以检查所有属性 .

    Results

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

    结果表明这些属性是 numpy nd arrays .

相关问题