我使用 5 个交叉验证和 F1 指标来评估我的神经网络。
但是,在 Jupyter Labs 中运行我的代码时,它似乎永远加载。不产生任何输出,但运行其他任务很好。
我总共有 5 次折叠,500 个 epoch。 每 50 个时期,我输出均方误差损失值(每折 x10)。在 500 个 epochs(1 倍)之后,我输出我给它的任何测试集的当前 F1 值。
import numpy as np
from sklearn.model_selection import cross_val_score
from sklearn import metrics
lr = 0.01
cross_val_score(lr,x_train,y_train,cv=5,scoring='mean_squared_error')
f1s = [] # to capture F1 score for every Fold
kf = KFold(n_splits=5)
for train, test in kf.split(x):
for epoch in range(500):
ridge.fit(x[train], y[train])
if epoch % 50 == 0: # prints MSE 10 times over each fold
print(mean_squared_error(y[test], ridge.predict(x[test])))
print("MSE: " + metrics.mean_squared_error(predictions, y))
f1 = metrics.f1_score(predictions, y) # appends each fold
f1s.append(f1)
print("F1: " + f1)
print("Average F1: " + np.mean(macro_f1))
注意:由于我的计算机规格较低,fold 和 epoch 值较低。我正在使用 Jupyter 实验室。
我做错了什么让这个永远运行?