Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class LengthTransformer(TransformerMixin):
- def transform(self, X, **transform_params):
- length = pd.DataFrame(X.apply(lambda x: len(x)))
- return length
- def fit(self, X, y=None, **fit_params):
- return self
- pipeline = Pipeline([('features', FeatureUnion([
- ('ngram_tf_idf', Pipeline([
- ('vect', CountVectorizer()),
- ('tfidf', TfidfTransformer())
- ])),
- ('length',LengthTransformer())
- ])),
- ('clf', clf),])
- vectorizer_name = 'fpath'+name
- joblib.dump(pipeline.steps[0][1],vectorizer_name+'_vect_'+str(int(accuracy*100)) +'.pkl')
- vect_file = "MultinomialNB_vect_80.pkl"
- vect = joblib.load(vect_file)
- AttributeError Traceback (most recent call last)
- <ipython-input-4-a5d89ba85002> in <module>()
- 4 vect_file = "MultinomialNB_vect_80.pkl"
- ----> 5 vect_n = joblib.load(vect_file)
- 6 print(vect_n)
- 7 # tfid = vect_n.steps[1][1]
- ~/anaconda2/envs/py35/lib/python3.5/site-packages/sklearn/externals/joblib/numpy_pickle.py in load(filename, mmap_mode)
- 576 return load_compatibility(fobj)
- 577
- --> 578 obj = _unpickle(fobj, filename, mmap_mode)
- 579
- 580 return obj
- ~/anaconda2/envs/py35/lib/python3.5/site-packages/sklearn/externals/joblib/numpy_pickle.py in _unpickle(fobj, filename, mmap_mode)
- 506 obj = None
- 507 try:
- --> 508 obj = unpickler.load()
- 509 if unpickler.compat_mode:
- 510 warnings.warn("The file '%s' has been generated with a "
- ~/anaconda2/envs/py35/lib/python3.5/pickle.py in load(self)
- 1041 raise EOFError
- 1042 assert isinstance(key, bytes_types)
- -> 1043 dispatch[key[0]](self)
- 1044 except _Stop as stopinst:
- 1045 return stopinst.value
- ~/anaconda2/envs/py35/lib/python3.5/pickle.py in load_global(self)
- 1340 module = self.readline()[:-1].decode("utf-8")
- 1341 name = self.readline()[:-1].decode("utf-8")
- -> 1342 klass = self.find_class(module, name)
- 1343 self.append(klass)
- 1344 dispatch[GLOBAL[0]] = load_global
- ~/anaconda2/envs/py35/lib/python3.5/pickle.py in find_class(self, module, name)
- 1394 return _getattribute(sys.modules[module], name)[0]
- 1395 else:
- -> 1396 return getattr(sys.modules[module], name)
- 1397
- 1398 def load_reduce(self):
- AttributeError: module '__main__' has no attribute 'LengthTransformer'
Add Comment
Please, Sign In to add comment