为什么我的系数只有一维?

2024-04-19 19:38:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我想对一些复习资料做一个感性的分析。响应变量为“正”或“负”。我运行了我的模型,我的系数只有一个维度,我认为应该是两个,因为有两个响应变量。感谢您的帮助,找出原因。你知道吗

from nltk.corpus import stopwords
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import BernoulliNB
from sklearn import cross_validation
from sklearn.metrics import classification_report
import numpy as np
from sklearn.metrics import accuracy_score
import textblob as TextBlob



#scikit
comments = list(['happy','sad','this is negative','this is positive', 'i like this', 'why do i hate this'])
classes = list(['positive','negative','negative','positive','positive','negative'])


# preprocess creates the term frequency matrix for the review data set
stop = stopwords.words('english')
count_vectorizer = CountVectorizer(analyzer =u'word',stop_words = stop, ngram_range=(1, 3))
comments = count_vectorizer.fit_transform(comments)
tfidf_comments = TfidfTransformer(use_idf=True).fit_transform(comments)


# preparing data for split validation. 60% training, 40% test
data_train,data_test,target_train,target_test = cross_validation.train_test_split(tfidf_comments,classes,test_size=0.2,random_state=43)
classifier = BernoulliNB().fit(data_train,target_train)

classifier.coef_.shape

最后一行打印出来(1L,6L)。我试图找出消极和积极的信息特征,但由于它的1L将给我提供相同的信息,这两种反应。你知道吗

谢谢你!你知道吗


Tags: fromtestimporttargetdatatrainsklearnthis