我想保存sklearn管道。为此,我这样做
outfile = open('model', 'wb')
pickle.dump(pipe, outfile)
然后我关闭笔记本,再次打开它,然后尝试
outfile = open('model' ,'rb')
model = pickle.load(outfile)
但是我得到Can't get attribute 'predictors' on <module '__main__'>
我代码的相关部分:
# Custom transformer using spaCy
class predictors(TransformerMixin):
def transform(self, X, **transform_params):
# Cleaning Text
return [clean_text(text) for text in X]
def fit(self, X, y=None, **fit_params):
return self
def get_params(self, deep=True):
return {}
# Basic function to clean the text
def clean_text(text):
# Removing spaces and converting text into lowercase
return text.strip().lower()
管道:
# Create pipeline using Bag of Words
pipe = Pipeline([("cleaner", predictors()),
('vectorizer', tfidf_vector),
('clf', clf)])