Custom Scenarios (Popularity Recommendation)
You can use retrieval and ranking algorithms provided by RES to customize a scenario tailored to your business environment.
The following examples use popularity recommendation to demonstrate how to customize scenarios. The most common popularity recommendation scenarios include e-commerce best seller rankings and leaderboards of video websites.
With just a few steps and some simple calculations, you can customize a typical scenario where items or content are recommended based on popularity. With the help of RES's built-in popularity ranking algorithm that measures behavior comprehensively, you can quickly obtain information on what is popular.
Before you start, carefully complete the preparations described in Preparations. To obtain recommendation results in custom scenarios, perform the following steps:
- Step 1: Preparing Data
- Step 2: Creating an Offline Data Source
- Step 3: Creating a Custom Scenario
- Step 4: Publishing a Custom Scenario
- Step 5: Obtaining Prediction Results
- Step 6: Deleting Related Resources to Avoid Unnecessary Charging
Preparations
- You have registered a HUAWEI CLOUD account that is not in arrears or frozen.
- You have created buckets and folders in OBS for storing sample data.
For details on how to create an OBS bucket and folder, see Creating a Bucket and Creating a Folder. Ensure that the OBS directory you use and RES are in the same region.
Step 1: Preparing Data
RES provides a sample dataset named test-data used in the "You May Also Like" scenario. This example uses this dataset to build a model. Perform the following operations to upload the dataset to the created OBS directory.
- Click sample data to download the test-data dataset to the local PC.
- Decompress the test-data package to the test-data directory on the local PC.
- Upload all files in the test-data folder to the OBS path created in preparation. For details, see Uploading a File.
Step 2: Creating an Offline Data Source
After the data is downloaded and uploaded to OBS, you need to create a data source for later calculations. The procedure is as follows:
- Log in to the RES management console. Choose Data Sources from the left navigation bar. The Data Sources page is displayed.
- Click Create. On the displayed page, enter a data source name and click
to select an OBS path that stores the data. Figure 1 Creating an offline data source
- After selecting the path, click Create Now.
- Return to the data source list and locate the data source you just created to perform data quality management. See Data Source Quality Management in the RES User Guide. The created data source is available only after data exploration is complete and a data quality report is generated.
Step 3: Creating a Custom Scenario
- Log in to the RES console. Choose Recommendation Scenarios > Custom Scenarios from the left navigation bar. On the displayed page, click Create.
- On the Basic Info page, configure the basic information, data range, and scenario specifications. After you complete all settings, click Next: Configure Retrieval Strategy.
- Scenario Name: Customize a scenario name, for example, hot-scene.
- Scenario Type: Select User-based item recommendation.
- Service Type: Select Recommendation Engine.
- Data Source: Select the data source created in step 2.
- Data Range: Set Selecting Data and Item Type. For the parameter Selecting Data, select behavior data of the N days before the latest date to calculate user preferences. (You are advised to set this parameter to a value greater than or equal to 30.)
- Scenario Specifications: Because the amount of test data used in this example is small, retain the default scenario specifications here. For the parameter Concurrent Online Services, set the max. number of online service invokings that are allowed per second. Figure 2 Configuring basic information
- On the Retrieval Strategy page, click Add and select Comprehensive behavior popularity - based recommendation. On the strategy details page, set parameters as required.
- Name: Customize a name, for example, hot-recall.
- Behavior Statistics Method: uv indicates unique visitors, counting the number of individual users who access a site within the reporting period. Only one record is generated for a visitor, regardless of how often they visit. pv indicates page views or clicks, measuring the number of web pages visited by website users. The same behavior records are not deduplicated.
- Ranking Algorithm Type: The options are normal and time. normal indicates that the item popularity does not weaken with time. time indicates that the popularity weakens with time. If you select time, Weak Gravity Factor is set to 1.8 by default.
- Max. Recommendation Results: Specify the number of results to be retrieved. Figure 3 Creating a retrieval strategy
- After you set all parameters, click OK. Then, click Next: Filter Rule and Next: Ranking Strategy. Filter rule and ranking strategy are optional. You can skip over them and go directly to the Online Service page.
- Click Add, configure the online process flow and click OK.
- Online Process Flow: Customize an online process name, for example, hot-flow.
- Candidate Set of Recommendations: Select hot-recall-DIREC created in step 2.
- Filter (Blacklist): Optional. Offline Filter is enabled in this example to filter recommendation results.
- Behavior Filter: Set Time Range (days) to 3 and Behavior Type to View. In this case, the items viewed by users in the last three days are excluded in the recommendation results. The behavior filter can enrich the recommendation result set, especially in the short video field. In the recommendation list, recently viewed videos are excluded to avoid repeated recommendations. Figure 4 Adding an online process flow
Step 4: Publishing a Custom Scenario
- After you complete the creation of a custom scenario, go back to the custom scenario list and locate the scenario you just created. In this example, locate hot-scene created in Step 3: Creating a Custom Scenario.
- Click Publish in the Operation column.
- The custom scenario is published successfully when it is in the Running status. Figure 5 Publishing a scenario
Step 5: Obtaining Prediction Results
After the online service is executed successfully, access the service to send a prediction request for test.
- On the Custom Scenarios page, locate the target scenario and click its name to go to the scenario details page.
- Click the Predict tab.
- Select Code and enter the prediction code in the Code text box. Click Predict. Prediction results that have undergone ranking processing appear on the right.
This is a test service. To ensure useful test results, use the user ID in the test data for prediction. The recommended user ID is user894.
Figure 6 Prediction result
- Prediction code
{ "id":"user894", "rec_num": 10 } - Prediction result
{ "flow_id": "hot-flow", "rec_num": 10, "candidates": [ { "id": "item332", "score": 1, "source": "hot-recall-DIREC" }, { "id": "item709", "score": 0.995, "source": "hot-recall-DIREC" }, { "id": "item338", "score": 0.99, "source": "hot-recall-DIREC" }, { "id": "item960", "score": 0.98499995, "source": "hot-recall-DIREC" }, { "id": "item469", "score": 0.97999996, "source": "hot-recall-DIREC" }, { "id": "item236", "score": 0.97499996, "source": "hot-recall-DIREC" } ] }
- Prediction code
Step 6: Deleting Related Resources to Avoid Unnecessary Charging
To avoid unnecessary charging, you are advised to delete related resources, such as the custom scenarios, data sources, and OBS directories after trial use.
- On the Data Sources page, locate data sources you no longer need and click Delete in the Operation column to delete them.
- On the Custom Scenarios page, locate custom scenarios you no longer need and click Delete in the Operation column to delete them. When a custom scenario is deleted, the corresponding retrieval strategies and online services are removed as well.
- To delete data, access OBS, delete the uploaded data, and delete the corresponding folders and OBS buckets.
Last Article: Intelligent Scenarios (You May Also Like)
Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.