def test_python_errors(rating_true, rating_pred): with pytest.raises(ValueError): rmse(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): mae(rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_user="******") with pytest.raises(ValueError): rsquared(rating_true, rating_pred, col_item="not_item") with pytest.raises(ValueError): exp_var(rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_item="not_item") with pytest.raises(ValueError): precision_at_k(rating_true, rating_pred, col_rating="not_rating") with pytest.raises(ValueError): recall_at_k(rating_true, rating_pred, col_prediction="not_prediction") with pytest.raises(ValueError): ndcg_at_k(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): map_at_k(rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_user="******")
def test_python_errors(python_data): rating_true, rating_pred, _ = python_data(binary_rating=False) with pytest.raises(ValueError): rmse(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): mae(rating_pred, rating_pred, col_rating=PREDICTION_COL, col_user="******") with pytest.raises(ValueError): rsquared(rating_true, rating_pred, col_item="not_item") with pytest.raises(ValueError): exp_var(rating_pred, rating_pred, col_rating=PREDICTION_COL, col_item="not_item") with pytest.raises(ValueError): precision_at_k(rating_true, rating_pred, col_rating="not_rating") with pytest.raises(ValueError): recall_at_k(rating_true, rating_pred, col_prediction="not_prediction") with pytest.raises(ValueError): ndcg_at_k(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): map_at_k(rating_pred, rating_pred, col_rating=PREDICTION_COL, col_user="******")
def test_python_exp_var(python_data, target_metrics): rating_true, rating_pred, _ = python_data assert exp_var( rating_true=rating_true, rating_pred=rating_true, col_prediction="rating" ) == pytest.approx(1.0, TOL) assert exp_var(rating_true, rating_pred) == target_metrics["exp_var"]
def test_python_exp_var(rating_true, rating_pred): assert exp_var( rating_true=rating_true, rating_pred=rating_true, col_prediction=DEFAULT_RATING_COL, ) == pytest.approx(1.0, TOL) assert exp_var(rating_true, rating_pred) == pytest.approx(-6.4466, TOL)
def test_python_errors(rating_true, rating_pred): with pytest.raises(ValueError): rmse(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): mae(rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_user="******") with pytest.raises(ValueError): rsquared(rating_true, rating_pred, col_item="not_item") with pytest.raises(ValueError): exp_var( rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_item="not_item" ) with pytest.raises(ValueError): precision_at_k(rating_true, rating_pred, col_rating="not_rating") with pytest.raises(ValueError): recall_at_k(rating_true, rating_pred, col_prediction="not_prediction") with pytest.raises(ValueError): ndcg_at_k(rating_true, rating_true, col_user="******") with pytest.raises(ValueError): map_at_k( rating_pred, rating_pred, col_rating=DEFAULT_PREDICTION_COL, col_user="******" )
def test_python_exp_var(python_data, target_metrics): rating_true, rating_pred, _ = python_data(binary_rating=False) assert exp_var(rating_true=rating_true, rating_pred=rating_true, col_prediction=DEFAULT_RATING_COL) == pytest.approx( 1.0, TOL) assert exp_var(rating_true, rating_pred) == target_metrics["exp_var"]
def rating_metrics_python(test, predictions): return { "RMSE": rmse(test, predictions, **COL_DICT), "MAE": mae(test, predictions, **COL_DICT), "R2": rsquared(test, predictions, **COL_DICT), "Explained Variance": exp_var(test, predictions, **COL_DICT), }
def rating_metrics_python(test, predictions): return { "RMSE": rmse(test, predictions, **COL_DICT), "MAE": mae(test, predictions, **COL_DICT), "R2": rsquared(test, predictions, **COL_DICT), "Explained Variance": exp_var(test, predictions, **COL_DICT) }
col_user='******', col_item='itemID', col_rating='rating') eval_mae = mae(test, top_k, col_user='******', col_item='itemID', col_rating='rating') eval_rsquared = rsquared(test, top_k, col_user='******', col_item='itemID', col_rating='rating') eval_exp_var = exp_var(test, top_k, col_user='******', col_item='itemID', col_rating='rating') positivity_threshold = 2 test_bin = test.copy() test_bin['rating'] = binarize(test_bin['rating'], positivity_threshold) top_k_prob = top_k.copy() top_k_prob['prediction'] = minmax_scale(top_k_prob['prediction'].astype(float)) eval_logloss = logloss(test_bin, top_k_prob, col_user='******', col_item='itemID', col_rating='rating')
# calculate some regression metrics eval_r2 = rsquared(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION) eval_rmse = rmse(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION) eval_mae = mae(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION) eval_exp_var = exp_var(test_df, scores, col_user=USER, col_item=ITEM, col_rating=RATING, col_prediction=PREDICTION) # print("Model:\t" + learn.__class__.__name__, # "RMSE:\t%f" % eval_rmse, # "MAE:\t%f" % eval_mae, # "Explained variance:\t%f" % eval_exp_var, # "R squared:\t%f" % eval_r2, sep='\n')