def test_distributional_coverage(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) d_coverage = evaluator.distributional_coverage() assert d_coverage == target_metrics["d_coverage"]
def test_catalog_coverage(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) c_coverage = evaluator.catalog_coverage() assert c_coverage == target_metrics["c_coverage"]
def test_serendipity(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId", col_relevance="Relevance", ) assert target_metrics["serendipity"] == evaluator.serendipity()
def test_user_diversity(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) actual = evaluator.user_diversity() assert_frame_equal( target_metrics["user_diversity"], actual, check_exact=False, check_less_precise=4, )
def test_novelty(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) novelty = evaluator.novelty() assert target_metrics["novelty"] == novelty assert novelty >= 0 # Test that novelty is zero when data includes only one item train_df_new = train_df.loc[train_df["ItemId"] == 3] reco_df_new = reco_df.loc[reco_df["ItemId"] == 3] evaluator = PythonDiversityEvaluation( train_df=train_df_new, reco_df=reco_df_new, col_user="******", col_item="ItemId" ) assert evaluator.novelty() == 0
def test_item_novelty(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) actual = evaluator.historical_item_novelty() assert_frame_equal( target_metrics["item_novelty"], actual, check_exact=False, check_less_precise=4 ) assert np.all(actual["item_novelty"].values >= 0) # Test that novelty is zero when data includes only one item train_df_new = train_df.loc[train_df["ItemId"] == 3] evaluator = PythonDiversityEvaluation( train_df=train_df_new, reco_df=reco_df, col_user="******", col_item="ItemId" ) actual = evaluator.historical_item_novelty() assert actual["item_novelty"].values[0] == 0
def test_diversity(python_diversity_data, target_metrics): train_df, reco_df = python_diversity_data evaluator = PythonDiversityEvaluation( train_df=train_df, reco_df=reco_df, col_user="******", col_item="ItemId" ) assert target_metrics["diversity"] == evaluator.diversity()