python - 我在 anaconda 程序中遇到 tensorflow 库问题
问题描述
有 1000 个数据,在这 1000 个数据中,670 个是训练数据,330 个是测试数据。
model.fit(x_train, y_train, epochs = 250)
当我写这篇文章时,它应该是 670 个火车数据,但在我的情况下是 21 个。
代码
import pandas as pd
dataFrame = pd.read_excel("bisiklet_fiyatlari.xlsx")
from sklearn.model_selection import train_test_split
y=dataFrame["Fiyat"].values
x=dataFrame[["BisikletOzellik1","BisikletOzellik2"]].values
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.33, random_state=15)
from sklearn.preprocessing import MinMaxScaler
scaler = MinMaxScaler()
scaler.fit(x_train)
x_train=scaler.transform(x_train)
x_test=scaler.transform(x_test)
import tensorflow as tf
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Dense
model = Sequential()
model.add(Dense(4, activation = "relu"))
model.add(Dense(4, activation = "relu"))
model.add(Dense(4, activation = "relu"))
model.add(Dense(1))
model.compile(optimizer="rmsprop",loss="mse")
model.fit(x_train, y_train, epochs = 250)
解决方案
您获得21/21
该fit
方法的步数的原因是,由于您没有batch_size
为该方法指定参数,因此它默认为 32(请参阅fit 方法的文档),并且 670/32 = 20,94大约为 21。
关于为什么您的损失如此之高,我无法通过提供的数据来判断,您需要显示哪些是数据,用于预处理它的代码等。
推荐阅读
- c++ - 这是 g++ 还是 clang++ 中的错误
- angular - i18n Translate.instant 带参数
- django - ats.views.index 视图没有返回 HttpResponse 对象。它返回 None 而不是
- mongodb - 猫鼬和猫鼬的区别
- python - 根据嵌套列表的索引将元素附加到嵌套列表中
- postgresql - 表和列命名约定 Postgres Dart-Aqueduct
- python - Python - 字体显示所有正方形
- android - kotlin 缺少 GoogleMap 的方法
- jquery - 在单击 jquery 时将背景图像设置为名称属性不起作用
- json - 为什么从对象“从不”检索函数的参数