如何一起使用k折的交叉验证和加权随机采样器?
我正在尝试使用pytorch(data_loader)训练我的分类模型(3类) 因此,我的第一个问题是数据没有平衡,所以我使用了加权随机采样器:
class_weights = [5,1,1]
sample_weights = [0] * len(ds)
for idx in enumerate(ds):
class_weight = class_weights[idx[1]['targets']]
sample_weights[idx[0]] = class_weight
sampler = WeightedRandomSampler(sample_weights, num_samples=
len(sample_weights), replacement=True)
DataLoader( ds, batch_size=batch_size, sampler=sampler, num_workers=2 )
但是现在我还有另一个问题,即过度拟合,所以我想使用 k折的交叉验证
有人可以帮助我,我真的不知道该怎么做!
I'm trying to train my classification model(3 classes) using PyTorch (data_loader)
so my first problem was that the data was not balanced so I used Weighted Random Sampler :
class_weights = [5,1,1]
sample_weights = [0] * len(ds)
for idx in enumerate(ds):
class_weight = class_weights[idx[1]['targets']]
sample_weights[idx[0]] = class_weight
sampler = WeightedRandomSampler(sample_weights, num_samples=
len(sample_weights), replacement=True)
DataLoader( ds, batch_size=batch_size, sampler=sampler, num_workers=2 )
but now I have another problem which is the overfitting so I want to use K-fold cross-validation
can someone help me cus I really don't know how to do it!?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论