Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CD-BPR
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Arthur Batel
CD-BPR
Commits
21ec35c3
Commit
21ec35c3
authored
1 year ago
by
Céline Robardet
Browse files
Options
Downloads
Patches
Plain Diff
notebook
parent
669545a4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
code/binary_bpr/BPR_model.py
+6
-8
6 additions, 8 deletions
code/binary_bpr/BPR_model.py
code/binary_bpr/main.py
+3
-3
3 additions, 3 deletions
code/binary_bpr/main.py
code/binary_bpr/script.py
+1
-0
1 addition, 0 deletions
code/binary_bpr/script.py
with
10 additions
and
11 deletions
code/binary_bpr/BPR_model.py
+
6
−
8
View file @
21ec35c3
...
@@ -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)
This diff is collapsed.
Click to expand it.
code/binary_bpr/main.py
+
3
−
3
View file @
21ec35c3
...
@@ -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
)
...
...
This diff is collapsed.
Click to expand it.
code/binary_bpr/script.py
+
1
−
0
View file @
21ec35c3
...
@@ -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
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment