0

我正在使用 Kfold 方法。我有一个大小为 1035 的数据集。我想确保我的模型不会过度拟合,因为我得到了 100% 的测试准确度,如果我增加 epoch,它会达到 100% 的测试准确度,然后又回到 77%。我还实施了提前停止,但我设置的耐心水平无法达到那里,因为它正在学习的每次迭代和耐心数量都会被重置。有人可以建议我该怎么做吗?我的模型有问题吗?我尝试改变学习率,但它影响了我的 ROC 曲线,但我得到了 100% 的测试准确率。

class convnet(nn.Module):
def __init__(self,num_inputs=9950,num_latent=200):
    super(convnet,self).__init__()
    
    self.num_inputs=num_inputs                
    
    
    self.fc_encoder= nn.Sequential( 
        nn.Linear(num_inputs,4975)
    )
    self.decoder = nn.Sequential(
        nn.Linear(4975,num_inputs)
    )
    self.con1=nn.Conv1d(1, 2, 5)
    self.max1=nn.MaxPool1d(4)
    self.con2=nn.Conv1d(2, 4, 5)
    self.max2=nn.MaxPool1d(4)
    self.l1=nn.Linear(2480,1024)
    self.drop=nn.Dropout(p= 0.5)
    self.l2=nn.Linear(1024,512)
    self.l3=nn.Linear(512,128)
    self.l4=nn.Linear(128,32)
    self.l5=nn.Linear(32,1)   
    
def forward(self, x):
    
    # print(x.shape)
    x = self.fc_encoder(x)
    # print("After Encoder",x.shape)
    x = self.decoder(x)

    # print("After Decoder",x.shape)
    x=x.unsqueeze(1)
    # print("After Decoder and Unsequeeze",x.shape)
    x=self.con1(x)
    x=self.max1(x)
    x=self.con2(x)
    x=self.max2(x)
    x = x.view(x.size(0), -1)
    x=self.l1(x)
    x=self.drop(x)
    x=self.l2(x)
    x=self.l3(x)
    x=self.l4(x)
    x=self.l5(x)


    # print("After CNN",x.shape)
    
    return torch.sigmoid(x)
4

0 回答 0