示例#1
0
# limitations under the License.
# ============================================================================
"""
Example for Visual Bayesian Personalized Ranking (VBPR)
Original data: http://jmcauley.ucsd.edu/data/tradesy/
"""

import cornac
from cornac.datasets import tradesy
from cornac.data import ImageModality
from cornac.eval_methods import RatioSplit

# VBPR extends Bayesian Personalized Randing to leverage item visual features (extracted from product images using CNN)
# The necessary data can be loaded as follows
feedback = tradesy.load_feedback()
features, item_ids = tradesy.load_feature()  # BIG file

# Instantiate a ImageModality, it makes it convenient to work with visual auxiliary information
# For more details, please refer to the tutorial on how to work with auxiliary data
item_image_modality = ImageModality(features=features,
                                    ids=item_ids,
                                    normalized=True)

# Define an evaluation method to split feedback into train and test sets
ratio_split = RatioSplit(
    data=feedback,
    test_size=0.1,
    rating_threshold=0.5,
    exclude_unknowns=True,
    verbose=True,
    item_image=item_image_modality,
示例#2
0
# -*- coding: utf-8 -*-

"""
Example for Visual Bayesian Personalized Ranking
Original data: http://jmcauley.ucsd.edu/data/tradesy/

@author: Quoc-Tuan Truong <*****@*****.**>
"""

import cornac
from cornac.datasets import tradesy
from cornac.data import ImageModule
from cornac.eval_methods import RatioSplit


item_feature = tradesy.load_feature() # BIG file
item_image_module = ImageModule(id_feature=item_feature, normalized=True)

ratio_split = RatioSplit(data=tradesy.load_data(),
                         test_size=0.1, rating_threshold=0.5,
                         exclude_unknowns=True, verbose=True,
                         item_image=item_image_module)

vbpr = cornac.models.VBPR(k=10, k2=20, n_epochs=50, batch_size=100, learning_rate=0.005,
                          lambda_w=1, lambda_b=0.01, lambda_e=0.0, use_gpu=True)

auc = cornac.metrics.AUC()
rec_50 = cornac.metrics.Recall(k=50)

exp = cornac.Experiment(eval_method=ratio_split,
                        models=[vbpr],