-
Notifications
You must be signed in to change notification settings - Fork 60
/
Copy pathRunExample.py
26 lines (24 loc) · 1.11 KB
/
RunExample.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import matplotlib.pyplot as plt
import numpy as np
from LoadData import load_rating_data, spilt_rating_dat
from sklearn.model_selection import train_test_split
from ProbabilisticMatrixFactorization import PMF
if __name__ == "__main__":
file_path = "data/ml-100k/u.data"
pmf = PMF()
pmf.set_params({"num_feat": 10, "epsilon": 1, "_lambda": 0.1, "momentum": 0.8, "maxepoch": 10, "num_batches": 100,
"batch_size": 1000})
ratings = load_rating_data(file_path)
print(len(np.unique(ratings[:, 0])), len(np.unique(ratings[:, 1])), pmf.num_feat)
train, test = train_test_split(ratings, test_size=0.2) # spilt_rating_dat(ratings)
pmf.fit(train, test)
# Check performance by plotting train and test errors
plt.plot(range(pmf.maxepoch), pmf.rmse_train, marker='o', label='Training Data')
plt.plot(range(pmf.maxepoch), pmf.rmse_test, marker='v', label='Test Data')
plt.title('The MovieLens Dataset Learning Curve')
plt.xlabel('Number of Epochs')
plt.ylabel('RMSE')
plt.legend()
plt.grid()
plt.show()
print("precision_acc,recall_acc:" + str(pmf.topK(test)))