等级: 新手上路
- 注册:
- 2024-1-22
- 曾用名:
|
请老师帮忙看一下这个代码问题:
python神经网络模型代码如下,运行后报错如附件所示。
注释model.fit(X_train, y_train, epochs=10, batch_size=64)这一行后不再报错。
python版本3.7.4,各python模块库均已安装。
顺便问一下能不能查看更详细的错误信息?
from PythonApi import *
import numpy as np
import pandas as pd
from sklearn.model_selection import train_test_split
import tensorflow as tf
from tensorflow.keras import layers
import tensorflow.keras
import random
from sklearn.preprocessing import StandardScaler
def init(context):
data1 = [[1,1],[2,2],[3,3],[4,4],[5,5]]
data2 = [1,2,3,4,5]
X = np.array(data1) # 特征矩阵
y = np.array(data2) # 目标向量
# 划分训练集和测试集
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
#数据预处理
ss = StandardScaler()
X_train = ss.fit_transform(X_train)
y_train = np.log1p(y_train) # 取对数归一化,提高拟合效果
X_test = ss.transform(X_test)
y_test = np.log1p(y_test) # 取对数归一化,提高拟合效果
# 定义神经网络模型
model = tf.keras.Sequential()
model.add(layers.Dense(16))
model.add(layers.Dense(32))
model.add(layers.Dense(1))
model.compile(optimizer=tf.keras.optimizers.SGD(0.001), loss='mean_squared_error')
model.fit(X_train, y_train, epochs=10, batch_size=64) ######此行注释后不报错
def before_trading(context):
pass
def handle_bar(context):
pass
def after_trading(context):
pass
|
-
|