我已经实现了一个用于特征提取的稀疏自动编码器,然后根据自学习的学习方法我无法理解如何从自动编码器中提取减少特征并将其与softmax-regression分类器一起使用。 这是我的自动编码器代码:
from keras.layers import Input, Dense
from keras.models import Model
from keras import regularizers
import matplotlib.pyplot as plt
ncol = df_train.shape[1]
input_dim = Input(shape = (ncol, ))
# DEFINE THE DIMENSION OF ENCODER ASSUMED 3
encoding_dim = 61
# DEFINE THE ENCODER LAYER
encoded = Dense(encoding_dim, activation ='relu',activity_regularizer=regularizers.l1(10e-5))(input_dim)
encoded = Dense(int(encoding_dim / 2), activation="relu")(encoded)
# DEFINE THE DECODER LAYER
decoded = Dense(int(encoding_dim / 2), activation='relu')(encoded)
decoded = Dense(ncol, activation = 'sigmoid')(encoded)
# COMBINE ENCODER AND DECODER INTO AN AUTOENCODER MODEL
autoencoder = Model(input = input_dim, output = decoded)
# CONFIGURE AND TRAIN THE AUTOENCODER
autoencoder.compile(optimizer = 'adadelta', loss ='binary_crossentropy',metrics=['accuracy'])
history = autoencoder.fit(df_train, df_train, nb_epoch = 100, batch_size = 32, shuffle = True, validation_data = (df_test, df_test)).history
使用此代码从编码器中提取特征:
# THE ENCODER TO EXTRACT THE REDUCED DIMENSION FROM THE ABOVE AUTOENCODER
encoder = Model(input = input_dim, output = encoded)
encoded_input = Input(shape = (encoding_dim, ))
encoded_out_train = encoder.predict(df_train)
encoded_out_test = encoder.predict(df_test)
但当我使用这些功能来训练和测试我的softmx回归分类器时,它给出准确度= 0.43。