def test_amazon_toy(self): random.seed(time.time()) if random.random() > 0.8: ratings = toy.load_feedback() sentiments = toy.load_sentiment() self.assertEqual(len(ratings), 167597) self.assertEqual(len(sentiments), 149877)
import os import glob import cornac import numpy as np from cornac.utils import cache from cornac.models import ComparERObj from cornac.metrics import AUC, Recall, NDCG from cornac.datasets import amazon_toy from cornac.experiment import Experiment from cornac.data.reader import Reader from cornac.eval_methods import StratifiedSplit from cornac.data.sentiment import SentimentModality rating = amazon_toy.load_feedback(fmt="UIRT", reader=Reader(min_user_freq=10)) sentiment_data = amazon_toy.load_sentiment() md = SentimentModality(data=sentiment_data) eval_method = StratifiedSplit( rating, group_by="user", chrono=True, sentiment=md, test_size=0.2, val_size=0.16, exclude_unknowns=True, verbose=True, ) pretrained_mter_model_path = "dist/toy/result/EFM"
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ """Example for Multi-Task Explainable Recommendation""" from cornac.datasets import amazon_toy from cornac.data import SentimentModality from cornac.eval_methods import RatioSplit from cornac.metrics import NDCG, RMSE from cornac.models import MTER from cornac import Experiment # Load rating and sentiment information data = amazon_toy.load_feedback() sentiment = amazon_toy.load_sentiment() # Instantiate a SentimentModality, it makes it convenient to work with sentiment information md = SentimentModality(data=sentiment) # Define an evaluation method to split feedback into train and test sets eval_method = RatioSplit( data, test_size=0.2, rating_threshold=1.0, sentiment=md, exclude_unknowns=True, verbose=True, seed=123, )
# # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ """Example for Explicit Factor Models""" import cornac from cornac.datasets import amazon_toy from cornac.data import SentimentModality from cornac.eval_methods import RatioSplit # Load rating and sentiment information rating = amazon_toy.load_feedback() sentiment = amazon_toy.load_sentiment() # Instantiate a SentimentModality, it make it convenient to work with sentiment information md = SentimentModality(data=sentiment) # Define an evaluation method to split feedback into train and test sets split_data = RatioSplit(data=rating, test_size=0.15, exclude_unknowns=True, verbose=True, sentiment=md, seed=123) # Instantiate the EFM model efm = cornac.models.EFM(num_explicit_factors=40,