我正在准备将输入信息输入到Keras神经网络中,以解决以下多类问题:
encoder = LabelEncoder()
encoder.fit(y)
encoded_Y = encoder.transform(y)
# convert integers to dummy variables (i.e. one hot encoded)
dummy_y = np_utils.to_categorical(encoded_Y)
X_train, X_test, y_train, y_test = train_test_split(X, dummy_y, test_size=0.2, random_state=42)
X_train, X_val, y_train, y_val = train_test_split(X_train, y_train, test_size=0.06, random_state=42)
训练模型之后,我尝试运行以下行以获得反映原始班级名称的预测:
y_pred = model.predict_classes(X_test)
y_pred = encoder.inverse_transform(y_pred)
y_test = np.argmax(y_test, axis = 1)
y_test = encoder.inverse_transform(y_test)
但是,作为培训和验证的对立面,我获得的准确度极低(0.36),达到0.98。这是将类转换回原始标签的正确方法吗?
我将精度计算为:
# For training
history.history['acc']
# For testing
accuracy_score(y_test, y_pred)