如何使用Joblib保存神经网络模型

时间:2019-08-04 22:57:05

标签: machine-learning neural-network pickle joblib

我正在尝试使用joblib将我的Neuro_network模型保存在熊猫中,因为它可以给我96%的准确性。我的数据集有9列-预测乳腺癌的功能。

y_train_categorical = to_categorical(y_train)
y_test_categorical = to_categorical(y_test)

from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense

neural_model = Sequential()
neural_model.add(Dense(units=6, activation='relu', input_dim=9))
neural_model.add(Dense(units=2, activation='softmax')) 

neural_model.compile(optimizer='adam',
              loss='categorical_crossentropy',
              metrics=['accuracy'])

neural_model = neural_model.fit(
    X_train_scaled,
    y_train_categorical,
    epochs=200,
    shuffle=True,
    verbose=2
)

from sklearn.externals import joblib 

joblib.dump(neural_model, 'neural.pkl') 
# also tried dump(neural_model, 'neural.joblib')```

Error message: can't pickle _thread.RLock objects

1 个答案:

答案 0 :(得分:1)

不建议使用pickle或cPickle保存Keras模型。

您只需要这样做:model.save(filepath)

有关更多信息,请查看documentation