gpt4 book ai didi

python - 深度学习中的值错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:40:07 25 4
gpt4 key购买 nike

在选择纪元后,我收到此错误:ValueError:输入数组应具有与目标数组相同数量的样本。找到5516个输入样本和12870个目标样本。欢迎任何建议。提前致谢

我使用的数据集包含很多分类变量,在创建虚拟变量后它们加起来为 95,在我选择纪元数之前的代码运行完美,然后出现此错误,此错误的原因是什么,这很重要,一,我将来可以使用它,2,我无法继续:)

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

dataset = pd.read_csv('zrpl_data.csv')
X = dataset.iloc[:, 0:6].values
y = dataset.iloc[:, 6].values

from sklearn.preprocessing import LabelEncoder, OneHotEncoder
labelencoder_X_1 = LabelEncoder()
X[:, 0] = labelencoder_X_1.fit_transform(X[:, 0])

labelencoder_X_2 = LabelEncoder()
X[:, 1] = labelencoder_X_2.fit_transform(X[:, 1])
labelencoder_X_3 = LabelEncoder()
X[:, 2] = labelencoder_X_1.fit_transform(X[:, 2])

labelencoder_X_4 = LabelEncoder()
X[:, 3] = labelencoder_X_1.fit_transform(X[:, 3])

labelencoder_X_5 = LabelEncoder()
X[:, 4] = labelencoder_X_1.fit_transform(X[:, 4])

onehotencoder = OneHotEncoder(categorical_features = [0,1,2,3,4])
X = onehotencoder.fit_transform(X).toarray()
X = X[:, 1:]

from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(X,y,test_size=0.3,
random_state = 0)

from sklearn.preprocessing import StandardScaler
sc = StandardScaler()
X_train = sc.fit_transform(X_train)
X_test = sc.transform(X_test)

import keras
from keras.models import Sequential
from keras.layers import Dense

classifier = Sequential()

classifier.add(Dense(output_dim=47,
init='uniform',activation='relu',input_dim=95))

classifier.add(Dense(output_dim=47, init='uniform',activation='relu'))
classifier.add(Dense(output_dim=1,
init='uniform',activation='sigmoid'))

classifier.compile(optimizer='adam', loss='binary_crossentropy', metrics=['accuracy'])

classifier.fit (X_train, y_train, batch_size=10,nb_epoch=100)

最佳答案

您有 5516 个特征样本和 12870 个目标样本(应该相等),在训练模型之前仔细检查它们的维度。

关于python - 深度学习中的值错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52924669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com