mirror of
https://github.com/RustyRaptor/Python-Machine-Learning-Second-Edition.git
synced 2026-12-04 00:15:20 -07:00
commit
This commit is contained in:
1 parent
09cae8e082
commit
9be5173182
299 files changed
+46939
No files matched your search
@@ -0,0 +1,22 @@
|
||||
from sklearn.feature_extraction.text import HashingVectorizer
|
||||
import re
|
||||
import os
|
||||
import pickle
|
||||
|
||||
|
||||
stop = pickle.load(open('stopwords.pkl', 'rb'))
|
||||
|
||||
|
||||
def tokenizer(text):
|
||||
text = re.sub('<[^>]*>', '', text)
|
||||
emoticons = re.findall('(?::|;|=)(?:-)?(?:\)|\(|D|P)',
|
||||
text.lower())
|
||||
text = re.sub('[\W]+', ' ', text.lower()) + \
|
||||
' '.join(emoticons).replace('-', '')
|
||||
tokenized = [w for w in text.split() if w not in stop]
|
||||
return tokenized
|
||||
|
||||
vect = HashingVectorizer(decode_error='ignore',
|
||||
n_features=2**21,
|
||||
preprocessor=None,
|
||||
tokenizer=tokenizer)
|
||||
Reference in new issue
Block a user