# http://www.apache.org/licenses/LICENSE-2.0 # # 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. # ============================================================================ import cornac from cornac.datasets import movielens from cornac.eval_methods import RatioSplit from cornac.models import IBPR # Load the MovieLens 1M dataset ml_1m = movielens.load_1m() # Instantiate an evaluation method. ratio_split = RatioSplit(data=ml_1m, test_size=0.2, rating_threshold=1.0, exclude_unknowns=True, verbose=True) # Instantiate a IBPR recommender model. ibpr = IBPR(k=10, init_params={'U': None, 'V': None}, verbose=True) # Instantiate evaluation metrics. rec_20 = cornac.metrics.Recall(k=20) pre_20 = cornac.metrics.Precision(k=20) # Instantiate and then run an experiment. exp = cornac.Experiment(eval_method=ratio_split, models=[ibpr],
# 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 HFT with Movilen 1m dataset """ import cornac from cornac.data import Reader from cornac.datasets import movielens from cornac.eval_methods import RatioSplit from cornac.data import TextModality from cornac.data.text import BaseTokenizer plots, movie_ids = movielens.load_plot() ml_1m = movielens.load_1m(reader=Reader(item_set=movie_ids)) # build text module item_text_modality = TextModality(corpus=plots, ids=movie_ids, tokenizer=BaseTokenizer( sep='\t', stop_words='english'), max_vocab=5000, max_doc_freq=0.5) ratio_split = RatioSplit(data=ml_1m, test_size=0.2, exclude_unknowns=True, item_text=item_text_modality, verbose=True, seed=123)
# -*- coding: utf-8 -*- """ Example for Matrix Factorization with biases @author: Quoc-Tuan Truong <*****@*****.**> """ import cornac from cornac.datasets import movielens from cornac.eval_methods import RatioSplit ratio_split = RatioSplit(data=movielens.load_1m(), test_size=0.2, exclude_unknowns=False, verbose=True) mf = cornac.models.MF(k=10, max_iter=25, learning_rate=0.01, lambda_reg=0.02, use_bias=True, early_stop=True, verbose=True) mae = cornac.metrics.MAE() rmse = cornac.metrics.RMSE() exp = cornac.Experiment(eval_method=ratio_split, models=[mf], metrics=[mae, rmse], user_based=True) exp.run()
def test_movielens_1m(): # only run data download tests 20% of the time to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: ml_1m = movielens.load_1m() assert len(ml_1m) == 1000209
def test_load_1m(self): # only run data download tests 20% of the time to speed up frequent testing random.seed(time.time()) if random.random() > 0.8: ml_1m = movielens.load_1m() self.assertEqual(len(ml_1m), 1000209)