Skip to content
Snippets Groups Projects
Commit 21ec35c3 authored by Céline Robardet's avatar Céline Robardet
Browse files

notebook

parent 669545a4
No related branches found
No related tags found
No related merge requests found
...@@ -144,8 +144,6 @@ class BPRModel(nn.Module): ...@@ -144,8 +144,6 @@ class BPRModel(nn.Module):
if valid_data is not None and epoch % 5 == 0: if valid_data is not None and epoch % 5 == 0:
correctness, acc, users, auc, rmse = self.evaluate_model(valid_data, num_kc, valid_target) correctness, acc, users, auc, rmse = self.evaluate_model(valid_data, num_kc, valid_target)
if acc > best_acc: if acc > best_acc:
best_acc = acc best_acc = acc
best_ite = epoch best_ite = epoch
...@@ -160,14 +158,14 @@ class BPRModel(nn.Module): ...@@ -160,14 +158,14 @@ class BPRModel(nn.Module):
#acc = accuracy_score(all_labels, all_decisions) #acc = accuracy_score(all_labels, all_decisions)
print("Best iteration",best_ite) #print("Best iteration",best_ite)
print("Accuracy train",acc) #print("Accuracy train",acc)
return acc return acc
# Evaluate the model # Evaluate the model
def evaluate_model(self, test_triplets, num_kc, y_test): def evaluate_model(self, test_triplets, num_kc, y_test):
print("Evaluate") #print("Evaluate")
# Initialize counters for metrics # Initialize counters for metrics
precision = 0.0 precision = 0.0
nb_evals = 0.0 nb_evals = 0.0
...@@ -242,12 +240,12 @@ class BPRModel(nn.Module): ...@@ -242,12 +240,12 @@ class BPRModel(nn.Module):
#print(all_labels) #print(all_labels)
mse1 = mean_squared_error(all_labels, all_predictions) mse1 = mean_squared_error(all_labels, all_predictions)
#print(all_predictions) #print(all_predictions)
print("RMSE", np.sqrt(mse1)) #print("RMSE", np.sqrt(mse1))
#all_predictions = np.concatenate(all_predictions) #all_predictions = np.concatenate(all_predictions)
#all_labels = np.concatenate(all_labels) #all_labels = np.concatenate(all_labels)
# Compute AUC for the entire dataset # Compute AUC for the entire dataset
auc = roc_auc_score(all_labels, all_predictions) auc = roc_auc_score(all_labels, all_predictions)
print("AUC:", auc) #print("AUC:", auc)
print(np.isnan(all_decisions).sum()) #print(np.isnan(all_decisions).sum())
#print("cont",contingency_matrix(all_labels, all_decisions)) #print("cont",contingency_matrix(all_labels, all_decisions))
return (all_labels==all_decisions).astype(int),accuracy_score(all_labels, all_decisions) , users, auc, np.sqrt(mse1) #accuracy_score(all_labels, all_decisions) return (all_labels==all_decisions).astype(int),accuracy_score(all_labels, all_decisions) , users, auc, np.sqrt(mse1) #accuracy_score(all_labels, all_decisions)
...@@ -341,14 +341,14 @@ if __name__ == '__main__': ...@@ -341,14 +341,14 @@ if __name__ == '__main__':
auc_list.append(auc) auc_list.append(auc)
rmse_list.append(rmse) rmse_list.append(rmse)
doa_train.append(doa) doa_train.append(doa)
print("Doa on Train dataset:", doa) print("Doa:", doa)
print("AUC and RMSE on test dataset:", auc, rmse) print("AUC and RMSE:", auc, rmse)
new_embedding_value = bpr_model.user_embeddings.weight.clone().detach().cpu().numpy() new_embedding_value = bpr_model.user_embeddings.weight.clone().detach().cpu().numpy()
write_file_doa_test(FileNameTest_temp, new_embedding_value, test, y_test, dico_kc, dico_users, dico_items) write_file_doa_test(FileNameTest_temp, new_embedding_value, test, y_test, dico_kc, dico_users, dico_items)
doa = compute_doa(FileNameTest_temp) doa = compute_doa(FileNameTest_temp)
doa_test.append(doa) doa_test.append(doa)
print("Accuracy and Doa on test dataset:", acc, doa) #print("Accuracy and Doa on test dataset:", acc, doa)
print(acc_list) print(acc_list)
print(auc_list) print(auc_list)
......
...@@ -7,5 +7,6 @@ batchSize =[ 512, 512,512, 512,512,4000] ...@@ -7,5 +7,6 @@ batchSize =[ 512, 512,512, 512,512,4000]
learningRate = [0.01,0.01,0.01,0.01,0.01] learningRate = [0.01,0.01,0.01,0.01,0.01]
mode = [1,1,1,1,1] mode = [1,1,1,1,1]
for i in range(len(datasets)): for i in range(len(datasets)):
print(datasets[i])
cmd = 'python main.py --dataTrain ' + datasets[i] +'/train_valid_0.csv --dataTest ' + datasets[i] +'/test_0.csv --epochs ' + str(epochs[i]) +' --batchSize 512 --learningRate 0.01 --mode 1 --dataPath ' + dPath + " --embPath " + embDirPath cmd = 'python main.py --dataTrain ' + datasets[i] +'/train_valid_0.csv --dataTest ' + datasets[i] +'/test_0.csv --epochs ' + str(epochs[i]) +' --batchSize 512 --learningRate 0.01 --mode 1 --dataPath ' + dPath + " --embPath " + embDirPath
os.system(cmd) os.system(cmd)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment