Cannot save HardSamplingClassifier #544
Answered
by
raphaelsty
nehalAggarwal
asked this question in
Q&A
-
Beta Was this translation helpful? Give feedback.
Answered by
raphaelsty
Mar 29, 2021
Replies: 1 comment 2 replies
-
Hi @nehalAggarwal, Pickle does not allow serializing lambda function. The You can install Dill using: pip install dill from river import datasets
from river import evaluate
from river import imblearn
from river import linear_model
from river import metrics
from river import optim
from river import preprocessing
model = (
preprocessing.StandardScaler() |
imblearn.HardSamplingClassifier(
classifier=linear_model.LogisticRegression(),
p=0.1,
size=40,
seed=42,
)
) import dill
with open('./model.pkl', 'wb') as output_file:
dill.dump(model, output_file) import dill
with open('./model.pkl', 'rb') as input_file:
model = dill.load(input_file) |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
MaxHalford
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @nehalAggarwal,
Pickle does not allow serializing lambda function. The
HardSampling
class is one of the few classes in River to have a lambda function in it's source code. I suggest you to use the Dill library to serialize this model. Dill is more or less the same as Pickle, maybe a bit slower but allows to serialize lambda functions.You can install Dill using: