我正在尝试使用joblib来保存我的神经网络模型,该模型在pandas中使用,准确率达到96%。我的数据集有9列特征,用于预测乳腺癌。
y_train_categorical = to_categorical(y_train)y_test_categorical = to_categorical(y_test)from tensorflow.keras.models import Sequentialfrom tensorflow.keras.layers import Denseneural_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') # 也尝试过dump(neural_model, 'neural.joblib')```错误信息: can't pickle _thread.RLock objects
回答:
不建议使用pickle或cPickle来保存Keras模型。
你只需要这样做:model.save(filepath)
更多信息,请查看文档。