forked from thiagodepaulo/total
-
Notifications
You must be signed in to change notification settings - Fork 0
/
my_pipes.py
29 lines (23 loc) · 863 Bytes
/
my_pipes.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 1 10:24:48 2017
@author: thiagodepaulo
"""
from sklearn.pipeline import Pipeline
from preprocessor import Preprocessor
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.feature_extraction.text import TfidfTransformer
from sklearn.naive_bayes import MultinomialNB
from tempfile import mkdtemp
from sklearn.externals.joblib import Memory
def preprocessor_steps():
return [('preprocessor',Preprocessor()), ('countvectorizer',CountVectorizer()), ('tfidftransformer',TfidfTransformer())]
def mnb_pipes(cache=False):
memory=None
if cache:
cachedir = mkdtemp()
memory = Memory(cachedir=cachedir, verbose=10)
steps = preprocessor_steps()
steps.append(('multinomialnb',MultinomialNB()))
return Pipeline(steps, memory=memory)