question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Finding the precision and auc scores.

See original GitHub issue

I am building a recommendation model for user-article dataset where each interaction is represented by 1.

model = LightFM(loss='warp', item_alpha=ITEM_ALPHA, user_alpha=USER_ALPHA, no_components=NUM_COMPONENTS, learning_rate=LEARNING_RATE, learning_schedule=LEARNING_SCHEDULE)

model = model.fit(train, item_features=itemf, user_features=uf, epochs=NUM_EPOCHS, num_threads=NUM_THREADS)

print("train shape: ",train.shape) print("test shape: ",test.shape)

train shape: (25900, 790) test shape: (25900, 790)

My predict model looks like this:

predictions = model.predict( user_id, pid_array, user_features=uf, item_features=itemf, num_threads=4)

where pid_array are indexes of number of items

train_precision = precision_at_k(model, train, k=10).mean()

I am trying to predict the precision and subsequently want auc score also. But I get this error.

Traceback (most recent call last): File “new_light_fm.py”, line 366, in <module> train_precision = precision_at_k(model, train, k=10).mean() File “/home/nt/anaconda3/lib/python3.6/site-packages/lightfm/evaluation.py”, line 69, in precision_at_k check_intersections=check_intersections, File “/home/nt/anaconda3/lib/python3.6/site-packages/lightfm/lightfm.py”, line 807, in predict_rank raise ValueError(‘Incorrect number of features in item_features’) ValueError: Incorrect number of features in item_features

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:12

github_iconTop GitHub Comments

5reactions
DoronGicommented, Sep 6, 2018

There is no problem to do so. You build one dataset to which you fit all your users, user-features, items and item-features by calling fit and fit_partial. Similarly you call build_user_features and build_item_features to build the feature matrices for all users and items. Next you call build_interactions twice, once with the interactions of the first user group (1-11 months) to get the test interaction matrix, and the second time with the interactions of the second user group (12th month) to get the test matrix.

2reactions
adsk2050commented, Nov 2, 2020

I have a sparse matrix(train/test data) of shape (1407580, 235061), which means there are around 330Bn combinations of user_id and item_id. This is causing precision_at_k and others to take way too much time to calculate. I am thinking about calculating the precision at k only for a small set of data by writing code myself. Will this be good enough for model validation?

Read more comments on GitHub >

github_iconTop Results From Across the Web

F1 Score vs ROC AUC vs Accuracy vs PR AUC - Neptune.ai
The first big difference is that you calculate accuracy on the predicted classes while you calculate ROC AUC on predicted scores.
Read more >
ROC Curves and Precision-Recall Curves for Imbalanced ...
The Precision-Recall AUC score can be calculated using the auc() function in scikit-learn, taking the precision and recall values as arguments.
Read more >
Recall, Precision, F1, ROC, AUC, and everything - Medium
F1 Score combines Recall and Precision to one performance metric. ... To derive the ROC curve, you calculate the True Positive Rate (TPR) ......
Read more >
The Complete Guide to AUC and Average Precision - Glass Box
AUROC ranges from 0.5 (random model) to 1.0 (perfect model). Note that it is possible to calculate an AUROC less than 0.5 if...
Read more >
Compute the AUC of Precision-Recall Curve - Sin-Yi Chou
Average precision score average_precision ... y_score) # Use AUC function to calculate the area under the curve of precision recall curve ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found