多层感知器 (MLP) Keras 张量流模型

Multilayer Perceptron (MLP) Keras tensorflow model

我 运行 在我适合我的模型进行训练后遇到了一个问题。下面是我的代码

import pandas as pd
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.preprocessing import LabelEncoder
from sklearn import preprocessing
from tensorflow import keras
from keras.models import Sequential
from tensorflow.keras import layers
            
     
    
bitcoin_data = pd.read_csv("BitcoinHeistData.csv")
#first we'll need to normalize the dataset
normal = bitcoin_data
normalized_bitcoin_data=preprocessing.normalize(normal)
        
# make it into a dataframe
columns = bitcoin_data.columns
normalized_bitcoin_df = pd.DataFrame(normalized_bitcoin_data, columns=columns)
# start out splitting the data
xtrain = normalized_bitcoin_df
labels = normalized_bitcoin_df.drop('label', axis=1)
         
x, x_validate, y, y_validate = train_test_split(xtrain, labels, test_size=0.2, train_size=0.8)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.12, train_size=0.88)


*#This is my output for my variables so far. Exactly how I want to split it 70% - 20% - 10%
#X HERE SHAPE
#(838860, 10)
#x_test HERE SHAPE
#(100664, 10)
#x_validate HERE SHAPE
#(209715, 10)
#X x_train SHAPE
#(738196, 10)
#y HERE SHAPE
#(838860, 9)
#y_test HERE SHAPE
#(100664, 9)
#X y_validate SHAPE
#(209715, 9)
#X y_train SHAPE
#(738196, 9)*

model = Sequential()
     model.add(layers.Dense(64, activation='relu', kernel_initializer='glorot_normal', 
     bias_initializer='zeros', input_shape=(128,)))
     model.add(layers.BatchNormalization())
     model.add(layers.Dense(32, activation='relu', kernel_initializer='glorot_normal', 
     bias_initializer='zeros'))
     model.add(layers.BatchNormalization())
     model.add(layers.Dense(32, activation='relu', kernel_initializer='glorot_normal', 
     bias_initializer='zeros'))
     model.add(layers.Dense(32, activation='relu', kernel_initializer='glorot_normal', 
     bias_initializer='zeros'))
     model.add(layers.Dropout(0.4))
     model.add(layers.Dense(10, activation='softmax'))
     optimizer = keras.optimizers.RMSprop(lr=0.0005, rho=0)
     model.compile(optimizer=optimizer, loss='categorical_crossentropy', metrics=['accuracy'])
        
     model.fit(x_train, y_train, epochs=20, batch_size=128)
    

#当我 运行 我的 model.fit for x_train 和 y_train 时,我得到这个错误 ValueError。我不明白怎么办 绕过它虽然。任何帮助都会得到帮助

#ValueError:顺序层的输入 0 与层不兼容:预期的轴 -1 输入形状的值为 128 但收到的输入形状为 [None, 10]

输入层神经元数(input_shape 属性)必须等于x_train数据集(x_train.shape[1])的列数。此外,输出层中的神经元数必须等于 y_train(y_train.shape[1]).

的列数