def train(X, y, outpath=None, verbose=True):
def build(X, y=None):
"""
Inner build function that builds a single model.
"""
model = Pipeline([
('preprocessor', NLTKPreprocessor()),
('vectorizer', TfidfVectorizer(
tokenizer=identity, preprocessor=None, lowercase=False)),
('clf', OneVsRestClassifier(LinearSVC()))])
model.fit(X, y)
return model
# Label encode the targets
labels = preprocessing.MultiLabelBinarizer()
y = labels.fit_transform(y)
model = build(X, y)
model.labels_ = labels
if outpath:
with open(outpath, 'wb') as f:
pickle.dump(model, f)
if verbose:
print("Model written out to {}".format(outpath))
return model
sentenceClassifer.py 文件源码
python
阅读 25
收藏 0
点赞 0
评论 0
评论列表
文章目录