我正在尝试校准在keras中受883个课程训练的模型。
# Define model architecture
model = Sequential()
model.add(Dense(512,input_shape=(3,),activation="relu"))
model.add(BatchNormalization())
model.add(Dense(512,activation="relu"))
model.add(BatchNormalization())
model.add(Dense(883,activation="relu"))
model.add(Dense(883,activation="softmax"))
model = load_model("my_model.h5")
calib = CalibratedClassifierCV(model,method="sigmoid",cv="prefit")
calib.fit(X_train,y_train)
我得到了错误
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/calibration.py", line 163, in fit
calibrated_classifier.fit(X, y)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/calibration.py", line 345, in fit
df, idx_pos_class = self._preproc(X)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/sklearn/calibration.py", line 312, in _preproc
transform(self.base_estimator.classes_)
AttributeError: 'Sequential' object has no attribute 'classes_'
model.classes_似乎不存在,所以我做错了什么?
model.classes_
Traceback (most recent call last):
File "<input>", line 1, in <module>
AttributeError: 'Sequential' object has no attribute 'classes_'
任何帮助将不胜感激,谢谢
答案 0 :(得分:0)
您必须使用Scikit学习包装器。像这样:
from keras.wrappers.scikit_learn import KerasClassifier
def get_model():
return load_model("my_model.h5")
model = KerasClassifier(build_fn = get_model, epochs=1, batch_size =10)
cv_model = CalibratedClassifierCV(model, method="sigmoid",cv="prefit")