我使用pandas傻瓜将类标签转换为一个热编码变量,并做出了模型预测。预测采用一种热编码形式,如何将预测转换为正常的类向量
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
import keras
from keras import Sequential
from keras.layers import Dense
df = pd.read_csv('./datasets/train.csv', header=0)
data = pd.read_csv('./datasets/test.csv', header=0)
"""
==============================================
preparing the training set
==============================================
"""
df = df.drop(['ID_code'], axis=1)
data_labels = data['ID_code']
data = data.drop(['ID_code'], axis=1)
"""
==============================================
preparing the test set
==============================================
"""
y = df['target'].values
y = pd.get_dummies(y) # oneHotEncode y
X = np.delete(df.values, 0, axis=1)
data = data.values
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=0)
model = Sequential()
model.add(Dense(units=1000, activation='relu', input_dim=200))
model.add(Dense(units=500, activation='relu'))
model.add(Dense(units=200, activation='relu'))
model.add(Dense(units=2, activation='softmax'))
model.compile(
loss="categorical_crossentropy",
optimizer=keras.optimizers.Adam(lr=0.001),
metrics=['accuracy']
)
n_epochs = 5
history = model.fit(X_train, y_train, epochs=n_epochs, batch_size=1000, validation_data=(X_test, y_test))
# now to predict the classes of the output
predictions = model.predict(data)
我如何获得将预测更改回y的原始形式的信息。