Package recombee_api_client :: Package api_requests :: Module recommend_items_to_user
[hide private]
[frames] | no frames]

Source Code for Module recombee_api_client.api_requests.recommend_items_to_user

  1  from recombee_api_client.api_requests.request import Request 
  2  import uuid 
  3   
  4  DEFAULT = uuid.uuid4() 
  5   
6 -class RecommendItemsToUser(Request):
7 """ 8 Based on user's past interactions (purchases, ratings, etc.) with the items, recommends top-N items that are most likely to be of high value for a given user. 9 10 It is also possible to use POST HTTP method (for example in case of very long ReQL filter) - query parameters then become body parameters. 11 12 """ 13
14 - def __init__(self, user_id, count, filter=DEFAULT, booster=DEFAULT, cascade_create=DEFAULT, scenario=DEFAULT, return_properties=DEFAULT, included_properties=DEFAULT, diversity=DEFAULT, min_relevance=DEFAULT, rotation_rate=DEFAULT, rotation_time=DEFAULT, expert_settings=DEFAULT):
15 """ 16 Required parameters: 17 @param user_id: ID of the user for which personalized recommendations are to be generated. 18 19 @param count: Number of items to be recommended (N for the top-N recommendation). 20 21 22 Optional parameters: 23 @param filter: Boolean-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to filter recommended items based on the values of their attributes. 24 25 @param booster: Number-returning [ReQL](https://docs.recombee.com/reql.html) expression which allows you to boost recommendation rate of some items based on the values of their attributes. 26 27 @param cascade_create: If the user does not exist in the database, returns a list of non-personalized recommendations and creates the user in the database. This allows for example rotations in the following recommendations for that user, as the user will be already known to the system. 28 29 @param scenario: Scenario defines a particular application of recommendations. It can be for example "homepage", "cart" or "emailing". You can see each scenario in the UI separately, so you can check how well each application performs. The AI which optimizes models in order to get the best results may optimize different scenarios separately, or even use different models in each of the scenarios. 30 31 @param return_properties: With `returnProperties=true`, property values of the recommended items are returned along with their IDs in a JSON dictionary. The acquired property values can be used for easy displaying of the recommended items to the user. 32 33 34 Example response: 35 36 ``` 37 38 E{lb} 39 40 "recommId": "ce52ada4-e4d9-4885-943c-407db2dee837", 41 42 "recomms": 43 44 [ 45 46 E{lb} 47 48 "id": "tv-178", 49 50 "values": E{lb} 51 52 "description": "4K TV with 3D feature", 53 54 "categories": ["Electronics", "Televisions"], 55 56 "price": 342, 57 58 "url": "myshop.com/tv-178" 59 E{rb} 60 E{rb}, 61 62 E{lb} 63 64 "id": "mixer-42", 65 66 "values": E{lb} 67 68 "description": "Stainless Steel Mixer", 69 70 "categories": ["Home & Kitchen"], 71 72 "price": 39, 73 74 "url": "myshop.com/mixer-42" 75 E{rb} 76 E{rb} 77 78 ] 79 E{rb} 80 81 ``` 82 83 84 @param included_properties: Allows to specify, which properties should be returned when `returnProperties=true` is set. The properties are given as a comma-separated list. 85 86 87 Example response for `includedProperties=description,price`: 88 89 ``` 90 91 E{lb} 92 93 "recommId": "a86ee8d5-cd8e-46d1-886c-8b3771d0520b", 94 95 "recomms": 96 97 [ 98 99 E{lb} 100 101 "id": "tv-178", 102 103 "values": E{lb} 104 105 "description": "4K TV with 3D feature", 106 107 "price": 342 108 E{rb} 109 E{rb}, 110 111 E{lb} 112 113 "id": "mixer-42", 114 115 "values": E{lb} 116 117 "description": "Stainless Steel Mixer", 118 119 "price": 39 120 E{rb} 121 E{rb} 122 123 ] 124 E{rb} 125 126 ``` 127 128 129 @param diversity: **Expert option** Real number from [0.0, 1.0] which determines how much mutually dissimilar should the recommended items be. The default value is 0.0, i.e., no diversification. Value 1.0 means maximal diversification. 130 131 132 @param min_relevance: **Expert option** Specifies the threshold of how much relevant must the recommended items be to the user. Possible values one of: "low", "medium", "high". The default value is "low", meaning that the system attempts to recommend number of items equal to *count* at any cost. If there are not enough data (such as interactions or item properties), this may even lead to bestseller-based recommendations to be appended to reach the full *count*. This behavior may be suppressed by using "medium" or "high" values. In such case, the system only recommends items of at least the requested relevancy, and may return less than *count* items when there is not enough data to fulfill it. 133 134 135 @param rotation_rate: **Expert option** If your users browse the system in real-time, it may easily happen that you wish to offer them recommendations multiple times. Here comes the question: how much should the recommendations change? Should they remain the same, or should they rotate? Recombee API allows you to control this per-request in backward fashion. You may penalize an item for being recommended in the near past. For the specific user, `rotationRate=1` means maximal rotation, `rotationRate=0` means absolutely no rotation. You may also use, for example `rotationRate=0.2` for only slight rotation of recommended items. Default: `0.1`. 136 137 138 @param rotation_time: **Expert option** Taking *rotationRate* into account, specifies how long time it takes to an item to recover from the penalization. For example, `rotationTime=7200.0` means that items recommended less than 2 hours ago are penalized. Default: `7200.0`. 139 140 141 @param expert_settings: Dictionary of custom options. 142 143 144 """ 145 self.user_id = user_id 146 self.count = count 147 self.filter = filter 148 self.booster = booster 149 self.cascade_create = cascade_create 150 self.scenario = scenario 151 self.return_properties = return_properties 152 self.included_properties = included_properties 153 self.diversity = diversity 154 self.min_relevance = min_relevance 155 self.rotation_rate = rotation_rate 156 self.rotation_time = rotation_time 157 self.expert_settings = expert_settings 158 self.timeout = 3000 159 self.ensure_https = False 160 self.method = 'post' 161 self.path = "/recomms/users/%s/items/" % (self.quote_path_param(self.user_id))
162
163 - def get_body_parameters(self):
164 """ 165 Values of body parameters as a dictionary (name of parameter: value of the parameter). 166 """ 167 p = dict() 168 p['count'] = self.count 169 if self.filter is not DEFAULT: 170 p['filter'] = self.filter 171 if self.booster is not DEFAULT: 172 p['booster'] = self.booster 173 if self.cascade_create is not DEFAULT: 174 p['cascadeCreate'] = self.cascade_create 175 if self.scenario is not DEFAULT: 176 p['scenario'] = self.scenario 177 if self.return_properties is not DEFAULT: 178 p['returnProperties'] = self.return_properties 179 if self.included_properties is not DEFAULT: 180 p['includedProperties'] = self.included_properties 181 if self.diversity is not DEFAULT: 182 p['diversity'] = self.diversity 183 if self.min_relevance is not DEFAULT: 184 p['minRelevance'] = self.min_relevance 185 if self.rotation_rate is not DEFAULT: 186 p['rotationRate'] = self.rotation_rate 187 if self.rotation_time is not DEFAULT: 188 p['rotationTime'] = self.rotation_time 189 if self.expert_settings is not DEFAULT: 190 p['expertSettings'] = self.expert_settings 191 return p
192
193 - def get_query_parameters(self):
194 """ 195 Values of query parameters as a dictionary (name of parameter: value of the parameter). 196 """ 197 params = dict() 198 return params
199