I have an n-gram model which uses a custom analyzer defined by a lambda function.
n=3
vect = CountVectorizer(analyzer=lambda x: (x[-i-1:] for i in range(0,min(n,len(x)))))
vect.fit(df.firstname)
I tried saving this model using pickle but I get the following error:
PicklingError Traceback (most recent call last)
<ipython-input-123-1bf65fd467e6> in <module>()
----> 1 pickle.dump(vect, open(n_gram_pickle_file, 'wb'))
PicklingError: Can't pickle <function <lambda> at 0x7f6d3f7ae6a8>: attribute lookup <lambda> on
__main__ failed
Can someone help me how to do this? Is there any other way to save the model other than pickling?