1

Do you know what would be the analog of doing something like this in Keras?

alpha = 5

pearson_corr = correlation.calculate_correlation(train) 
pearson_index = [x for x in range(len(pearson_corr)) if abs(pearson_corr[x])<0.3]
self.corr_l1_penalty = torch.sum(torch.sum(torch.abs(self.fc1.weight), dim = 0)[pearson_index]) #corr lasso (l1) penality
self.loss_fn = nn.MSELoss()
penalty = alpha * self.model.corr_l1_penalty
loss = self.loss_fn(y_pred, y_labels)+penalty

calculate_correlation is a custom function which computes the correlation coefficient between X and y within train.

Caterina
  • 775
  • 9
  • 26

0 Answers0