ValueError: Ошибка при проверке цели: ожидалось, что плотный_4 будет иметь форму (1,), но получил массив с формой (6,) - PullRequest
0 голосов
/ 12 июля 2020

Я делаю модель прогноза с использованием набора данных chroni c почечной болезни. Однако форма моего значения X_train кажется недействительной.

Я пытался изменить его, но получил ошибку кортежа

# import libraries 
import glob 
from keras.models import Sequential, load_model
import numpy as np
import pandas as pd
from keras.layers import Dense
from sklearn.preprocessing import LabelEncoder, MinMaxScaler
import matplotlib.pyplot as plt
import keras as k
from sklearn.model_selection import train_test_split

# load the data 
from google.colab import files
uploaded = files.upload()
df = pd.read_csv('kidney_disease.csv')

#print the first 5 rows of data
df.head(5)
# create a list of column names to keep 
columns_to_retain = ['sg', 'al', 'sc', 'hemo', 'pcv', 'wbcc', 'htn', 'classification']

# drop the unneccessary columns 
df = df.drop( [col for col in df.columns if not col in columns_to_retain], axis=1)

#drop the rows with na or missing values
df = df.dropna(axis=0)
# transform the non-numeric data in the columns
for column in df.columns:
  if df[column].dtype == np.number:
    continue
  df[column] = LabelEncoder().fit_transform(df[column])

# split the data into independent (X) dataset and dependent (y) dataset
X = df.drop(['classification'], axis=1)
y = df['classification']

# feature scaling
#min-max scaler method scales the dataset in order that all features lies between 0 and 1
X_scaler = MinMaxScaler()
X_scaler.fit(X)
column_names = X.columns
X[column_names] = X_scaler.transform(X)

# split the data into 80% training & 20% testing
X_train, y_train, X_test, y_test = train_test_split(X,y, test_size = 0.2, shuffle=True)# build the model
model = Sequential()
model.add( Dense(256, input_dim= len(X.columns), kernel_initializer=k.initializers.random_normal(seed=13), activation ='relu') )
model.add( Dense(1, activation = 'hard_sigmoid') )

# compiling the model (loss function mesures how well the model does in training 
# & tries to improve on it using the optimizer )
model.compile(loss='binary_crossentropy', optimizer='adam', metrics=['accuracy'])

# train the model
history = model.fit(X_train, y_train, epochs = 2000, batch_size= X_train.shape[0])

#print(X_train[0:1].shape)

У вас есть какие-нибудь идеи и объясните мне root этой проблемы.

Заранее спасибо!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...