def test_amazon_office(self): random.seed(time.time()) if random.random() > 0.8: ratings = office.load_feedback() contexts = office.load_graph() self.assertEqual(len(ratings), 53282) self.assertEqual(len(contexts), 108466)
"""Fit to and evaluate PCRL [1] on the Office Amazon dataset. [1] Salah, Aghiles, and Hady W. Lauw. Probabilistic Collaborative Representation Learning\ for Personalized Item Recommendation. In UAI 2018. """ from cornac.data import GraphModality from cornac.eval_methods import RatioSplit from cornac.experiment import Experiment from cornac import metrics from cornac.models import PCRL from cornac.datasets import amazon_office as office # PCRL jointly models user preferences and performs deep item features learning from auxiliary data (e.g., item relations). # The necessary data can be loaded as follows ratings = office.load_feedback() contexts = office.load_graph() # Instantiate a GraphModality, it make it convenient to work with graph (network) auxiliary information # For more details, please refer to the tutorial on how to work with auxiliary data item_graph_modality = GraphModality(data=contexts) # Define an evaluation method to split feedback into train and test sets ratio_split = RatioSplit(data=ratings, test_size=0.2, rating_threshold=3.5, exclude_unknowns=True, verbose=True, item_graph=item_graph_modality) # Instantiate PCRL pcrl = PCRL(k=100, z_dims=[300], max_iter=300, learning_rate=0.001)
# See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ """Fit to and evaluate MCF on the Office Amazon dataset""" from cornac.data import GraphModality from cornac.eval_methods import RatioSplit from cornac.experiment import Experiment from cornac import metrics from cornac.models import MCF from cornac.datasets import amazon_office as office # MCF leverages relationships among items, it jointly factorizes the user-item and item-item matrices # The necessary data can be loaded as follows ratings = office.load_feedback() item_net = office.load_graph() # Instantiate a GraphModality, it make it convenient to work with graph (network) auxiliary information # For more details, please refer to the tutorial on how to work with auxiliary data item_graph_modality = GraphModality(data=item_net) # Define an evaluation method to split feedback into train and test sets ratio_split = RatioSplit(data=ratings, test_size=0.2, rating_threshold=3.5, exclude_unknowns=True, verbose=True, item_graph=item_graph_modality) # Instantiate MCF mcf = MCF(k=10, max_iter=40, learning_rate=0.001, verbose=True) # Evaluation metrics