我正在创建一个函数作为GRU练习的一部分,以更多地了解python和GRU。我似乎遇到名称错误。
我已经阅读了许多有关在python中定义项目的文章,但是我认为我已经在其后的代码中对此进行了明确定义。
def workflow(EV_data, get_split, train_model, get_rmse,n_train = 250,n_test = 50,look_back = 1):
gX_train, gY_train, gX_test, gY_test, scaler, start_point = get_split(EV_data, n_train, n_test)
model = train_model(gX_train, gY_train, gX_test, gY_test)
RMSE, predictions = get_rmse(model, gX_test, gY_test, scaler, start_point, EV_data, n_train)
return RMSE, predictions
错误:
NameError: name 'predictions' is not defined
答案 0 :(得分:1)
所有内容都应该在函数定义块中。我试过了,并且编译正确:
def workflow(EV_data, get_split, train_model, get_rmse,n_train = 250,n_test = 50,look_back = 1):
gX_train, gY_train, gX_test, gY_test, scaler, start_point = get_split(EV_data, n_train, n_test)
model = train_model(gX_train, gY_train, gX_test, gY_test)
RMSE, predictions = get_rmse(model, gX_test, gY_test, scaler, start_point, EV_data, n_train)
return RMSE, predictions