python - Jupyter Lab 未执行 K 折交叉验证
问题描述
我正在使用 5 交叉验证和 F1 指标来评估我的神经网络。
但是,在 Jupyter Labs 中运行我的代码时,它似乎永远加载。不产生任何输出,但运行其他任务很好。
我总共有 5 折和 500 个 epoch。每 50 个时期,我输出均方误差损失值(每折叠 x10)。在 500 个 epoch(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))
注意:由于我的计算机规格较低,折叠和历元值较低。我正在使用 Jupyter 实验室。
我做错了什么导致它永远运行?
解决方案
推荐阅读
- php - 使用 PHP FPDF 换行长文本的问题
- swift - 如何从应用程序委托访问 NSViewController?
- azure - 使用 PowerShell ARM Cmdlet 授予 AKS 对 ACR 的访问权限
- php - 在原始查询 laravel 中使用 php 变量
- postgresql - postgresql - 内部联接无法正常工作
- oracle - Oracle 查询性能改进
- c# - 计算机图形学中的固定旋转
- c - 填充动态 char 数组会导致覆盖
- c# - 我的百分比值是在 c# 的文本框中打印“0”
- dialogflow-es - 使用 Google Assistant SDK 定制内置意图