Guest User

Untitled

a guest
Feb 22nd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. class LengthTransformer(TransformerMixin):
  2.  
  3. def transform(self, X, **transform_params):
  4. length = pd.DataFrame(X.apply(lambda x: len(x)))
  5. return length
  6.  
  7. def fit(self, X, y=None, **fit_params):
  8. return self
  9.  
  10. pipeline = Pipeline([('features', FeatureUnion([
  11. ('ngram_tf_idf', Pipeline([
  12. ('vect', CountVectorizer()),
  13. ('tfidf', TfidfTransformer())
  14. ])),
  15. ('length',LengthTransformer())
  16. ])),
  17. ('clf', clf),])
  18.  
  19. vectorizer_name = 'fpath'+name
  20.  
  21. joblib.dump(pipeline.steps[0][1],vectorizer_name+'_vect_'+str(int(accuracy*100)) +'.pkl')
  22.  
  23. vect_file = "MultinomialNB_vect_80.pkl"
  24. vect = joblib.load(vect_file)
  25.  
  26. AttributeError Traceback (most recent call last)
  27. <ipython-input-4-a5d89ba85002> in <module>()
  28. 4 vect_file = "MultinomialNB_vect_80.pkl"
  29. ----> 5 vect_n = joblib.load(vect_file)
  30. 6 print(vect_n)
  31. 7 # tfid = vect_n.steps[1][1]
  32.  
  33. ~/anaconda2/envs/py35/lib/python3.5/site-packages/sklearn/externals/joblib/numpy_pickle.py in load(filename, mmap_mode)
  34. 576 return load_compatibility(fobj)
  35. 577
  36. --> 578 obj = _unpickle(fobj, filename, mmap_mode)
  37. 579
  38. 580 return obj
  39.  
  40. ~/anaconda2/envs/py35/lib/python3.5/site-packages/sklearn/externals/joblib/numpy_pickle.py in _unpickle(fobj, filename, mmap_mode)
  41. 506 obj = None
  42. 507 try:
  43. --> 508 obj = unpickler.load()
  44. 509 if unpickler.compat_mode:
  45. 510 warnings.warn("The file '%s' has been generated with a "
  46.  
  47. ~/anaconda2/envs/py35/lib/python3.5/pickle.py in load(self)
  48. 1041 raise EOFError
  49. 1042 assert isinstance(key, bytes_types)
  50. -> 1043 dispatch[key[0]](self)
  51. 1044 except _Stop as stopinst:
  52. 1045 return stopinst.value
  53.  
  54. ~/anaconda2/envs/py35/lib/python3.5/pickle.py in load_global(self)
  55. 1340 module = self.readline()[:-1].decode("utf-8")
  56. 1341 name = self.readline()[:-1].decode("utf-8")
  57. -> 1342 klass = self.find_class(module, name)
  58. 1343 self.append(klass)
  59. 1344 dispatch[GLOBAL[0]] = load_global
  60.  
  61. ~/anaconda2/envs/py35/lib/python3.5/pickle.py in find_class(self, module, name)
  62. 1394 return _getattribute(sys.modules[module], name)[0]
  63. 1395 else:
  64. -> 1396 return getattr(sys.modules[module], name)
  65. 1397
  66. 1398 def load_reduce(self):
  67.  
  68. AttributeError: module '__main__' has no attribute 'LengthTransformer'
Add Comment
Please, Sign In to add comment