python - Sklearn 错误无法将大小为 6912 的数组重塑为形状 (614,154)
问题描述
我观看了有关如何构建您的第一个神经网络的视频,但在 27:00 ValueError: cannot reshape array of size 6912 into shape (614,154) 时遇到了这个错误
https://www.youtube.com/watch?v=S2sZNlr-4_4
代码如下:
# This algorithm detects if a person has diabetes or not
# Load libraries
from keras.models import Sequential
from keras.layers import Dense
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
plt.style.use('fivethirtyeight')
import pandas as pd
# load data
from google.colab import files
uploaded = files.upload()
# Store the dataset
df = pd.read_csv('datasets_4511_6897_diabetes.csv')
# convert the data into an array
dataset = df.values
# get all of the rows from the first eight columns of the dataset
X = dataset[:,0:8]
y = dataset[:,8]
# process the data
from sklearn import preprocessing
min_max_scaler = preprocessing.MinMaxScaler()
X_scale = min_max_scaler.fit_transform(X)
# split the data into 80% training and 20% testing
X_train, X_test, y_train, y_test = train_test_split(X_scale, y, test_size = 0.2, random_state = 4)
# build the model
model = Sequential([
Dense(12, activation ='relu', input_shape = (8,)),
Dense(15, activation = 'relu'),
Dense(1, activation = 'sigmoid')
])
#Compile the model (sgd = stochastic gradient descent)
model.compile(
optimizer = 'sgd',
loss = 'binary_crossentropy',
metrics=['accuracy']
)
# train the model
hist = model.fit(X_train, y_train, batch_size = 57, epochs = 1000, validation_split=0.2)
# evaluate the model on the training data set
from sklearn.metrics import classification_report, confusion_matrix, accuracy_score
pred = model.predict(X_train)
pred = [1 if y >= 0.5 else 0 for y in prediction]
#df = df.values.reshape(614,154)
print('confusion_matrix : /n', confusion_matrix(y_train, pred))
你知道如何处理这个问题吗?
先感谢您
解决方案
推荐阅读
- java - Json 到 Graphql 的转换
- html - 如何在 asp.net 项目中使用 html 标签
- java - 在春季重试中仅处理自定义异常
- scikit-learn - 如何在 python 中通过三个步骤定义管道:预处理、预测和后处理?
- java - 检查 Vector 的值是否在 Set 中
- java - Admob 横幅位置错误
- python - Python exe用户输入自动输入
- javascript - 使用 map 的并行请求和使用 promise.all 的 for 循环,然后
- ftp - 通过浏览器连接的 FTP 服务器,但在 FileZilla 中不工作
- google-cloud-speech - 谷歌语音转文本上的 504