Turi Create
4.0
|
#include <toolkits/sparse_similarity/sparse_similarity_lookup.hpp>
Public Member Functions | |
virtual std::string | similarity_name () const =0 |
virtual std::map< std::string, flexible_type > | train_from_sparse_matrix_sarray (size_t num_items, const std::shared_ptr< sarray< std::vector< std::pair< size_t, double > > > > &data)=0 |
virtual void | setup_by_raw_similarity (size_t num_items, const flex_list &item_data, const sframe &_interaction_data, const std::string &item_column, const std::string &similar_item_column, const std::string &similarity, bool add_reverse=false)=0 |
virtual size_t | score_items (std::vector< std::pair< size_t, double > > &item_predictions, const std::vector< std::pair< size_t, double > > &user_item_data) const =0 |
virtual void | get_similar_items (std::vector< std::pair< size_t, flexible_type > > &similar_items_dest, size_t item, size_t top_k) const =0 |
virtual void | save (turi::oarchive &oarc) const =0 |
const std::map< std::string, flexible_type > & | current_options () const |
virtual bool | _debug_check_equal (const sparse_similarity_lookup &other) const =0 |
Static Public Member Functions | |
static void | add_options (option_manager &options) |
static std::shared_ptr< sparse_similarity_lookup > | create (const std::string &similarity, const std::map< std::string, flexible_type > &options) |
Protected Attributes | |
std::map< std::string, flexible_type > | options |
A model that can be used for sparse similarity lookup.
A trained version of this model contains a lookup table of the nearest items to each item along with a similarity score. This allows both retrieval of the most similar items to a given item, and to generate a list of the items most similar to a collection of items. The latter is used to recommend items, e.g. by providing a list of the items and ratings for a particular user.
The similarity metrics are an implementation of a class that implements a number of methods dictating the math used in the accumulation. See similarities.hpp for details.
This model is creating using the create(...) methods below, which takes the name of the similarity and the current options. The options given in add_options(...) must be present in the options map.
The model can be trained by either providing the similarities of the items directly, or by training the model on a sarray of user-item-ratings. See the below functions for details.
Code Structure:
Definition at line 70 of file sparse_similarity_lookup.hpp.
|
pure virtual |
A method to detect if two sparse_similarity_lookup classes are essentially the same.
|
static |
Adds in all of the options needed for this class to the option manager.
|
static |
Factory method: Call this to create or load a model from one of the existing similarities by name.
|
inline |
The current options.
Definition at line 166 of file sparse_similarity_lookup.hpp.
|
pure virtual |
Fills an array with the most similar items to a given item. This is read directly from the lookup table. If fewer than top_k items are present in the lookup table, then only those in the lookup table are returned.
|
pure virtual |
Serialization in sparse_similarity_lookup_impl.
|
pure virtual |
Score all items in a list of item predictions given a list of user-item interactions. This method fills in the second part of the tuple for all the items in the item_predictions container.
This is also the way to generate values for predict –
Returns the number of item similarity pairs that were considered. (In some corner cases, such as when an item had no users that also rated other items, we want to recommend by popularity or some other metric).
|
pure virtual |
Sets the lookup tables directly from an sframe of interaction data. The interaction data is an sframe containing columns item_column, similar_item_column, and similarity. The items and similar items must be indices in {0, ..., num_items-1}.
An error is raised if the similarity value does not conform to the similarity chosen – e.g. jaccard similarity must be between 0 and 1.
If add_reverse is true, then all (i,j, rating) entries are also interpreted as (j, i, rating). Note that no duplicates can be present.
|
pure virtual |
Returns the name of the similarity this version uses.
Implemented in turi::sparse_sim::sparse_similarity_lookup_impl< SimilarityType >.
|
pure virtual |
Trains the model from an sarray of vectors of (index, score) pairs. Each row is assumed to be the user, and each index in the score is an item that the user rated. The similarity of a given item to another item is given by treating the user ratings of each item as a sparse vector and then measuring the similarity between them. This calculation is done as efficiently as possible using a combination of nearest neighbors search and lookup tables.
|
protected |
The stored options.
Definition at line 180 of file sparse_similarity_lookup.hpp.