def build_models_NLP(train_pos_vec, train_neg_vec):
"""
Returns a BernoulliNB and LosticRegression Model that are fit to the training data.
"""
Y = ["pos"]*len(train_pos_vec) + ["neg"]*len(train_neg_vec)
# Use sklearn's BernoulliNB and LogisticRegression functions to fit two models to the training data.
# For BernoulliNB, use alpha=1.0 and binarize=None
# For LogisticRegression, pass no parameters
train_vec = []
train_vec.extend(train_pos_vec)
train_vec.extend(train_neg_vec)
nb_model = BernoulliNB(alpha=1.0, binarize=None, class_prior=None, fit_prior=True)
nb_model.fit(train_vec, Y)
lr_model = LogisticRegression()
lr_model.fit(train_vec, Y)
return nb_model, lr_model
sentiment.py 文件源码
python
阅读 29
收藏 0
点赞 0
评论 0
评论列表
文章目录