【发布时间】:2019-03-04 19:15:15
【问题描述】:
import pandas as pd
import matplotlib.pyplot as plt
csv = 'C:\\Users\\Alex\\Downloads\\weight-height.csv'
df = pd.read_csv(csv)
df.head
x_train = df['Height'].values
#into centimetres because im english
x_train = x_train * 2.54
y_train = df['Weight'].values
#into kilos because im english
y_train = y_train / 2.2046226218
plt.figure()
plt.scatter(x_train, y_train, c=None)
plt.show()
print(X[:10])
print(y[:10])
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense, Activation
import numpy as np
X = np.array(x_train).reshape(-1,1)
y = np.array(y_train).reshape(-1,1)
X = X[:5000]
y = y[:5000]
model = Sequential()
model.add(Dense(36, activation='relu'))
model.add(Dense(18))
model.add(Dense(1))
model.compile(optimizer='adam',
loss='mean_squared_error',
metrics=['accuracy'])
history = model.fit(X,y, batch_size=1, epochs=1, validation_split=0.1)
#plt.plot(history.history['acc'])
#plt.plot(history.history['val_acc'])
我的问题几乎是我是一个菜鸟,我正在尝试使用 keras 从头开始创建自己的线性回归模型,但我不明白为什么我的损失如此之高。我需要知道它是我正在使用的优化器或损失函数还是数据问题。数据集只是体重和身高的列表。
【问题讨论】:
-
我建议尝试将一条直线拟合到两个数据点 - 这应该更容易排除故障,特别是如果您事先知道正确答案。
-
您正在为单个 epoch 进行训练,使用单个样本的批次,这是一个大问题。你应该训练更长时间。
标签: neural-network deep-learning artificial-intelligence linear-regression