Skip to content

Commit 9f77538

Browse files
committed
Update README.md
1 parent 6ad126d commit 9f77538

File tree

1 file changed

+105
-6
lines changed

1 file changed

+105
-6
lines changed

README.md

Lines changed: 105 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,27 @@
11
Sensible.PredictionIO.NET
22
=========================
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:
55

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
710

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
916
----------
1017
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.
1118

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:
1325
```
1426
var client = new Client(ConfigurationManager.AppSettings["apiUrl"], ConfigurationManager.AppSettings["appKey"]);
1527
for (var i = 1; i <= 10; i++)
@@ -24,12 +36,99 @@ for (var i = 1; i <= 10; i++)
2436
}
2537
```
2638

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)
56+
{
57+
Console.WriteLine(string.Format("Item {0} created", i.ToString()));
58+
}
59+
}
60+
```
61+
62+
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)
81+
{
82+
Console.WriteLine(string.Format("User {0} viewed item {1}", i.ToString(), item.ToString()));
83+
}
84+
}
85+
}
86+
```
87+
88+
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));
108+
}
109+
else
110+
{
111+
Console.WriteLine("An error occured. " + response.Content);
112+
}
113+
```
114+
115+
If everything goes as planned, PredictionIO will generate 10 recommended items for our user! Amazing, wasn't it?!
116+
117+
27118
Dependencies
28119
------------
29-
The only external dependency for this project is RestSharp, available on nuget via this command:
120+
The only external dependency for this project is [RestSharp], available on nuget via this command:
30121
```
31122
> Install-Package RestSharp
32123
```
33124

125+
Roadmap
126+
-------
127+
* support for start time/end time item attributes
128+
* support custom attributes for items
129+
130+
131+
34132
[PredictionIO]:http://prediction.io
35133
[Sensible]:http://www.sensible.gr
134+
[RestSharp]:http://restsharp.org

0 commit comments

Comments
 (0)