forked from NicolasHug/Surprise
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimilarity_conf.py
31 lines (23 loc) · 864 Bytes
/
similarity_conf.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
27
28
29
30
31
"""
This module gives an example of how to configure similarity measures
computation.
"""
from __future__ import (absolute_import, division, print_function,
unicode_literals)
from surprise import KNNBasic
from surprise import Dataset
from surprise.model_selection import cross_validate
# Load the movielens-100k dataset.
data = Dataset.load_builtin('ml-100k')
# Example using cosine similarity
sim_options = {'name': 'cosine',
'user_based': False # compute similarities between items
}
algo = KNNBasic(sim_options=sim_options)
cross_validate(algo, data, verbose=True)
# Example using pearson_baseline similarity
sim_options = {'name': 'pearson_baseline',
'shrinkage': 0 # no shrinkage
}
algo = KNNBasic(sim_options=sim_options)
cross_validate(algo, data, verbose=True)