本文整理汇总了Python中sklearn.naive_bayes.MultinomialNB.compile方法的典型用法代码示例。如果您正苦于以下问题:Python MultinomialNB.compile方法的具体用法?Python MultinomialNB.compile怎么用?Python MultinomialNB.compile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sklearn.naive_bayes.MultinomialNB
的用法示例。
在下文中一共展示了MultinomialNB.compile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: print
# 需要导入模块: from sklearn.naive_bayes import MultinomialNB [as 别名]
# 或者: from sklearn.naive_bayes.MultinomialNB import compile [as 别名]
print ("Method = KNN with word mover's distance as described in 'From Word Embeddings To Document Distances'")
model = WordMoversKNN(W_embed=embedding_weights , n_neighbors=3)
model.fit( train_matrix , train_labels )
results = model.predict( test_matrix )
print ("Accuracy = " + repr( sklearn.metrics.accuracy_score( test_labels , results ) ))
print (sklearn.metrics.classification_report( test_labels , results ))
print ("Method = MLP with bag-of-words features")
np.random.seed(0)
model = Sequential()
model.add(Dense(embeddings_dim, input_dim=train_matrix.shape[1], init='uniform', activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(embeddings_dim, activation='relu'))
model.add(Dropout(0.25))
model.add(Dense(1, activation='sigmoid'))
if num_classes == 2: model.compile(loss='binary_crossentropy', optimizer='adam', class_mode='binary')
else: model.compile(loss='categorical_crossentropy', optimizer='adam')
model.fit( train_matrix , train_labels , nb_epoch=30, batch_size=32)
results = model.predict_classes( test_matrix )
print ("Accuracy = " + repr( sklearn.metrics.accuracy_score( test_labels , results ) ))
print (sklearn.metrics.classification_report( test_labels , results ))
print ("Method = Stack of two LSTMs")
np.random.seed(0)
model = Sequential()
model.add(Embedding(max_features, embeddings_dim, input_length=max_sent_len, mask_zero=True, weights=[embedding_weights] ))
model.add(Dropout(0.1))
model.add(LSTM(output_dim=embeddings_dim , activation='relu', return_sequences=True, init='zero'))
model.add(Dropout(0.1))
model.add(LSTM(output_dim=embeddings_dim , activation='relu', init='zero'))
model.add(Dense(1,init='zero',activation='linear'))