请问一下,这里出现浮点数无法引用,TypeError: 'float' object is not subscriptable
for i_episode in range(MAX_EPISODES):
"""初始化s"""
random.seed(7)
fit = -1e5 # 全局最佳适应值
# 初始粒子适应度计算
print("计算初始全局最优")
for i in range(pN):
for j in range(dim):
V[i][j] = random.uniform(0, 1)
if j == 1:
X[i][j] = random.uniform(DOWN[j], UP[j])
else:
X[i][j] = round(random.randint(DOWN[j], UP[j]), 0)
pbest[i] = X[i]
le, pred, y_t = training_bus(X[i])
tmp = function(pred, y_t, le)
#其中bus函数是
def training_bus(x):
neurons = int(x[0])
dropout = round(x[1], 6)
batch_size = int(x[2])
model = build_model(neurons, dropout)
print('neurons:' + str(int(x[0])) + ' dropout:' + str(dropout) + ' batch_size:' + str(batch_size))
model.fit(
x_train,
y_train,
batch_size=batch_size,
epochs=10,
verbose=0)
trainScore = model_score(model, x_train, y_train,)
model_test_score(model, x_test, y_test)
# model.save('neurons' + str(int(X[0])) + '_dropout' + str(dropout) + '_batch_size' + str(batch_size) + '.h5')
finish = [int(X[0]), dropout, batch_size, round(trainScore, 6)]
model_scores.append(finish)
#writeOneCsv(finish, '模型参数效果比较.csv')
# 训练完成后可直接加载模型
# model_lstm = load_model('GRU_bus_' + str(X[0]) + '_' + str(X[1]) + '_' + str(X[2]) + '_' + '.h5')
pred = model.predict(x_test)
le = len(pred)
y_t = y_test.reshape(-1, 1)
# print(y_t.shape)
return le, pred, y_t
TypeError: 'float' object is not subscriptable
尝试str ,还是不对
le, pred, y_t = str(training_bus(X[i]))