You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+105-6Lines changed: 105 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,15 +1,27 @@
1
1
Sensible.PredictionIO.NET
2
2
=========================
3
-
Sensible.PredictionIO.NET is an open source C# wrapper for the PredictionIO API. If you are not already familiar
4
-
with [PredictionIO], it is an "open source machine learning server for software developers to create predictive features, such as personalization, recommendation and content discovery". This library supports version 0.7.0 at the time of writing.
3
+
Sensible.PredictionIO.NET is an open source C# wrapper for the [PredictionIO] API. If you are not already familiar
4
+
with PredictionIO, it is an "open source machine learning server for software developers to create predictive features, such as personalization, recommendation and content discovery". It is an amazing machine learning software which stands on the shoulder of giants such as Apache Mahout and MongoDB, and allows you to add features to your application such as:
5
5
6
-
This repo is maintained by Themos Piperakis from [Sensible]
6
+
* predict user behaviors
7
+
* offer personalized video, news, deals, ads and job openings
8
+
* help users to discover interesting events, documents, apps and restaurants
9
+
* provide impressive match-making services
7
10
8
-
Quickstart
11
+
Sensible.PredictionIO.NET supports PredictionIO version 0.7.0, but should be compatible with other versions as well.
12
+
13
+
This repo is maintained by Themos Piperakis from [Sensible].
14
+
15
+
Quick start
9
16
----------
10
17
You will need to have access to an instance of PredictionIO, either locally (e.g. via a vagrant VM), or online (e.g. AWS AMI). For installation instructions have a look the the [PredictionIO] website.
11
18
12
-
After you setup the PredictIO server, you will need to feed the engine with some sample data. There are two main concepts in PredictIO: users, and items. Let's first create 10 users for our sample application:
19
+
After you setup the PredictionIO server, you will first need to create an application through the admin panel. Make note of the application key generated. After that, create an item recommendation engine with the default algorithm (kNN), and name it itemrec.
20
+
21
+
Generating our sample data
22
+
--------------------------
23
+
24
+
You will then need to feed the engine with some sample data. There are two main concepts in PredictIO: users, and items. Let's first create 10 users for our sample application:
13
25
```
14
26
var client = new Client(ConfigurationManager.AppSettings["apiUrl"], ConfigurationManager.AppSettings["appKey"]);
15
27
for (var i = 1; i <= 10; i++)
@@ -24,12 +36,99 @@ for (var i = 1; i <= 10; i++)
24
36
}
25
37
```
26
38
39
+
In the code above, we need the apiUrl for the PredictionIO instance (e.g. http://127.0.0.1:8000) and the application key generated for the item recomenndation engine.
40
+
41
+
Since Sensible.PredictionIO.NET is based on [RestSharp], all requests follow the same philosophy: a Builder is first created from the corresponging class after passing the appropriate arguments. Then a RestClient is build with a .Build() method, and the response is returned after executing the .Execute() method. Of course, all our requests can be easily converted to asynchronous, just by using RestSharp's .ExecuteAsync()!
42
+
43
+
After our users are generated, we now need to add some items. Items have one or more item types, which in real life could represent a product category. In our example, "1" represents the item type.
44
+
45
+
```
46
+
for (var i = 1; i <= 50; i++)
47
+
{
48
+
var builder = client.AddItemRequestBuilder(new Item
49
+
{
50
+
ItemId = i.ToString(),
51
+
ItemTypes = new List<string> { "1" }
52
+
});
53
+
var request = builder.Build();
54
+
var response = request.Execute(builder.RestRequest);
55
+
if (response.StatusCode == HttpStatusCode.Created)
The last step to generate our sample data is to enter some user actions. A user action represents actions such as like, dislike, rate, etc. We are generating 10 random item actions for our users.
63
+
64
+
```
65
+
for (var i = 1; i <= 10; i++)
66
+
{
67
+
for (var j = 1; j <= 10; j++)
68
+
{
69
+
var item = new Random().Next(1, 51);
70
+
var builder = client.UserActionRequestBuilder(
71
+
new UserAction
72
+
{
73
+
UserId = i.ToString(),
74
+
ItemId = item.ToString(),
75
+
Action = UserAction.Actions.View
76
+
}
77
+
);
78
+
var request = builder.Build();
79
+
var response = request.Execute(builder.RestRequest);
80
+
if (response.StatusCode == HttpStatusCode.Created)
Our data is now ready. At this point, our model needs to be trained before being able to generate recommendations. By default PredictionIO is setup to train the model every hour, but you can force a manual training through the admin panel. Please refer to [PredictionIO] documentation for further details.
89
+
90
+
Generating a recommendation
91
+
---------------------------
92
+
93
+
When you see that the engine in in Running status, it's time to generate our first user recommendation. Let's get 10 recommended items for user 1.
94
+
95
+
```
96
+
var builder = client.ItemRecGetTopNRequestBuilder(
97
+
new RecommendationEngineRequest
98
+
{
99
+
UserId = "1",
100
+
Engine = "itemrec",
101
+
NumberOfItems = 10,
102
+
});
103
+
var request = builder.Build();
104
+
var response = request.Execute<EngineResponse>(builder.RestRequest);
105
+
if (response.StatusCode == HttpStatusCode.OK)
106
+
{
107
+
Console.WriteLine("Recommended items for user 1 are: " + string.Join(", ", response.Data.ItemIds));
0 commit comments