PredictionIO suggest to like items that have already been liked - ruby-on-rails

I'm trying to use PredictionIO recommendation engine in Rails app to suggest items for users to like. So, I have three models: user, product and favorite(user_id, product_id). This is what algorithms.json file looks like:
[
{
"name": "ncMahoutItemBased",
"params": {
"booleanData": true,
"itemSimilarity": "LogLikelihoodSimilarity",
"weighted": false,
"threshold": 0.6,
"nearestN": 10,
"unseenOnly": false,
"freshness" : 0,
"freshnessTimeUnit" : 86400
}
}
]
The things is, after training and deploying, I get a list of suggested items for user and some of which the user has already liked. Why is this?
What is the name for UserBased algorithm instead of "ncMahoutItemBased"?
Thanks.

There is nothing wrong with recommending an item the user has shown a preference for. This is expected behavior in a clothing store, where I always buy Levi's Jeans and they want to remind me of that.
In your case you may not want to recommend items already prefered so filter them out of the recommendations. In most Mahout recommenders this is done for you so PredictionIO must have disabled that feature. Is there some param or config option that tells PredictionIO to filter out a user's preferred items?

Related

how to create a new skill in twilio flex?

I'm trying to set up a webchat. I need to create different agents with different skills(eg: sales, marketing). I'm not able to find an option to create skills(and how to assign them to respective agents).
As far as I know there is no UI for creating skills. They are arbitrary strings you attach to worker attributes. If you go to task router -> workers -> select a worker you'll see somethings like:
{
"contact_uri": "client:joe_smith",
"full_name": "Joe Smith",
"image_url": "https://www.gravatar.com/avatar/0078cd9b02fc2550990c9c5c8f261c22?d=mp",
"email": "joe#example.com",
"roles": ["admin"],
"routing": { "skills": ["some_skill", "another_skill"] }
}
To add a skill add any string you want to the skills array in the worker attributes.
You can create Workers Skills direct by the Flex UI, accessing https://flex.twilio.com/admin/ > Skills and then create your skills. After create, you can access the https://flex.twilio.com/teams/ > Access Some Worker > Select the desired skills to attach it to the agent.
I hope that it help you.

Elasticsearch autocomplete with picture of product and other options

Recently I've started to learn elasticsearch and currently working with some sample product data. Now I want to suggest the product as user type it. I've checked some documentations for Completion Suggester and implemented some examples for completion.
I checked some benefits of using _suggest than normal _search like
SPEED
Real Time
Readability
Custom Ordering
Here is the script I tried:
`POST /products/_suggest
{
"product" : {
"text" : "fres",
"completion" : {
"field" : "name"
}
}
}`
But now, I want to implement suggester that will suggest as user type with the picture of product and some other options with product name like Add to cart etc
I am implementing all this with the help of elasticsearch-rails gem over ruby on rails.
So can I do it with normal completion type as it provides lots of feature over search or else normal search will be good for this scenario?
Elastic Search (ES) allows things that "normal search" won't: extended full text search end especially fuzzy search (a typo like 'hoem' can return 'home' anyway...).
But an ES query returns only data that is indexed in ES !
You will probably not index your pictures so you'll have to process the ES answer and generate a 'pretty' suggest listing with pictures (ES will return entries with both ES and ActiveRecord IDs)
Feel free to ask if you need more details

Calculating the Count of a related Collection

I have two models Professionals and Projects
Professionals hasMany Projects
Projects belongsTo Professionals
In the Professionals index page i need to show the number of projects the Professional has.
Right now i am doing the following query to get all the Professionals.
How can i fetch the count of the Projects of each of the Professionals as well.
#pros = Professionals.all.asc(:name)
I would add projects_count to Professional
Then
class Project
belongs_to :professional, counter_cache: true
end
And rails will handle the count every time a project is added to or removed from a professional. Then you can just do .projects_count on each professional.
Edit:
If you actually want additonal data
#pros = Professionals.includes(:projects).order(:name)
Then
#pros.each do |pro|
pro.name
pro.projects.each do |project|
project.name
end
end
I am just abstracting here because the rails thing really isn't my bag. But let's talk about schema and things to look for. And as such the code is really just "pseudo-code" but should be close to what is wanted.
Considering "just" how MongoDB is going to store the data, and that you presumably seem to have multiple collections. And I am not saying that is or is not the best model, but just dealing with it.
Let us assume we have this data for "Projects"
{
"_id" : ObjectId("53202e1d78166396592cf805"),
"name": "Project1,
"desc": "Building Project"
},
{
"_id" : ObjectId("532197fb423c37c0edbd4a52")
"name": "Project2",
"desc": "Renovation Project"
}
And that for "Professionals" we might have something like this:
{
"_id" : ObjectId("531e22b7ba53b9dd07756bc8"),
"name": "Steve",
"projects": [
ObjectId("53202e1d78166396592cf805"),
ObjectId("532197fb423c37c0edbd4a52")
]
}
Right. So now we see that the "Professional" has to have some kind of concept that there are related items in another collection and what those related items are.
Now I presume, (and it's not my bag) that there is a way to get down to the lower level of the driver implementation in Mongoid ( I believe that is Moped off the top of my head ) and that it likely ( from memory ) is invoked in a similar way to ( asssuming "Professionals" as the class model name ) :
Professionals.collection.aggregate([
{ "$unwind": "$projects" },
{ "$group": {
"_id": "$_id",
"count": { "$sum": 1 }
}
])
Or in some similar form that is more or less the analog to what you would do in the native mongodb shell. The point being, with something like this you just made the server do the work, rather than pulling all the results to you client and looping through them.
Suggesting that you use native code to iterate results from your data store is counter productive and counter intuitive do using any kind of back end database store. Whether it by a SQL database or a NoSQL database, the general preference is as long as the database has methods to do the aggregation work, then use them.
If you are writing code that essentially pulls every record from your store and then cycles through to get the result then you are doing something wrong.
Use the database methods. Otherwise you might as well just use a text file and be done with it.

Notifications or user activity log implementation

The application has certain actions that are recorded for each user and recorded in db table notifications. The table has the following structure:
user_id, notification_type, credit, timestamp
notification_type does not store the entire text of the notification but just stores a short type description.
Later when the user wants to view his notifications I use a helper method from my view to fetch the actual text.
def notification_text(type)
case type_id
when 'flagPositive'
return 'A question you flagged has been marked as correct.'
when 'qAccepted'
return 'A question you added has been accepted.'
when 'qModerated'
return 'You moderated a question.'
when 'flagReport'
return 'You moderated a flag.'
end
end
1) Is this an optimum way to do this?
2) Should I replace the type_description with integer values (say 1 -> flagPositive, 2-> qAccepted) for performance benefits?
3) Are there any best practices around the same that I should be following?
1) This highly depends on your application and requirements. What I can say is that I used this approach sometimes and faced no problems so far.
2) If you see a performance problem with the string lookup, you could do so. A general recommendation is to optimize performance only when really needed.
3) Just google for "Ruby", "Rails", "ActiveRecord" and "Enum". You'll find lots of discussions about different solutions for this kind of problem. There are similar questions on this site, e.g., Enums in Ruby or In Rails, how should I implement a Status field for a Tasks app - integer or enum?

Getting total count of FB Likes for a web-app page using Rails

I am building a rails app where there is an image gallery and users will be able to hit the facebook like button for each image they open. Each image can have its seperate page URL. I plan to use the facebook like plugin so that users can like the photos as web-pages. So far I was able to find that if I do https://graph.facebook.com/?id=http://www.mysite.com/ImagePage i get:
{
"id": "http://www.mysite.com/ImagePage",
"shares": 30
}
This leaves me with 2 problems.
The shares property is not exactly the total count of likes, it is only the count of times the link made it to the user's facebook wall. How do I get the number of likes?
Is there an eventHandler or something I can use to know when a user clicks Like? so that I can store that information? I want to store the likes count at my end so that I can show the gallery in the order of descending number of total likes in each day.
I have come across the rails Koala gem but I am not sure if I need to use that for my application yet, as I do not have the need to log in users using facebook login/connect. Please advise if you think I need to do so to do what I mentioned above.
you have to use FQL.
see this example in php, im sure you know how to handle it in ruby:
$fql = 'SELECT url, share_count, like_count, comment_count, total_count
FROM link_stat WHERE url="http://stackoverflow.com"';
$json = file_get_contents('https://api.facebook.com/method/fql.query?format=json&query=' . urlencode($fql));
result looks like:
[
{
"url" : "http://stackoverflow.com",
"share_count" : 1353,
"like_count" : 332,
"comment_count" : 538,
"total_count" : 2223
}
]
For those who don't know how to modify the code seen in the previous answer by yourself, you mostly have two choices:
Use facebook gems available that support running FQL queries (for example: fb_graph)
Sample code:
require 'fb_graph'
array = FbGraph::Query.new(
'SELECT name FROM user WHERE uid = me()'
).fetch(ACCESS_TOKEN)
p array
Use a simple Ruby code that basically just does FQL queries, as seen on this accepted answer (Facebook FQL Query with Ruby)

Resources