首页 > 解决方案 > 我在 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)

标签: pythontensorflow

解决方案


您获得21/21fit方法的步数的原因是,由于您没有batch_size为该方法指定参数,因此它默认为 32(请参阅fit 方法的文档),并且 670/32 = 20,94大约为 21。

关于为什么您的损失如此之高,我无法通过提供的数据来判断,您需要显示哪些是数据,用于预处理它的代码等。


推荐阅读