如何在 Python 中反转 one-hot 编码?
How to reverse one-hot encoding in Python?
我目前正在创建一个 CNN,该网络的主要任务是将输入信息分类为不同的 类。这些 类 是预测频率的精确值。
这是我到目前为止构建的:
def evaluate_model(X_train, Y_train, X_test, Y_test,n_filters):
verbose, epochs, batch_size = 1, 10, 3
n_timesteps, n_features = X_train.shape[1], X_train.shape[2]
model = Sequential()
model.add(Conv1D(filters=n_filters, kernel_size=8, activation='relu', input_shape=(n_timesteps,n_features)))
model.add(Conv1D(filters=n_filters, kernel_size=8, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(50, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
# fit network
history=model.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=verbose)
# evaluate model
_, accuracy = model.evaluate(X_test, Y_test, batch_size=batch_size, verbose=1)
return accuracy, model
predict=model.predict(amplitude_t)
print(predict)
我正在尝试预测我创建的一些完美运行的新信号的值。虽然我的输出是概率输出,但我想将其转换回实际频率值。有办法吗?
这是你需要做的:
predicted_labels = np.argmax(predict, 0)
如需进一步说明,请参阅此答案:
我目前正在创建一个 CNN,该网络的主要任务是将输入信息分类为不同的 类。这些 类 是预测频率的精确值。
这是我到目前为止构建的:
def evaluate_model(X_train, Y_train, X_test, Y_test,n_filters):
verbose, epochs, batch_size = 1, 10, 3
n_timesteps, n_features = X_train.shape[1], X_train.shape[2]
model = Sequential()
model.add(Conv1D(filters=n_filters, kernel_size=8, activation='relu', input_shape=(n_timesteps,n_features)))
model.add(Conv1D(filters=n_filters, kernel_size=8, activation='relu'))
model.add(Dropout(0.5))
model.add(MaxPooling1D(pool_size=2))
model.add(Flatten())
model.add(Dense(100, activation='relu'))
model.add(Dense(50, activation='softmax'))
model.compile(loss='categorical_crossentropy', optimizer='adam', metrics=['accuracy'])
print(model.summary())
# fit network
history=model.fit(X_train, Y_train, epochs=epochs, batch_size=batch_size, verbose=verbose)
# evaluate model
_, accuracy = model.evaluate(X_test, Y_test, batch_size=batch_size, verbose=1)
return accuracy, model
predict=model.predict(amplitude_t)
print(predict)
我正在尝试预测我创建的一些完美运行的新信号的值。虽然我的输出是概率输出,但我想将其转换回实际频率值。有办法吗?
这是你需要做的:
predicted_labels = np.argmax(predict, 0)
如需进一步说明,请参阅此答案: