concept user in category machine learning

This is an excerpt from Manning's book Grokking Machine Learning.
Recommending videos or movies to a user (for example YouTube, Netflix, etc.).
What do we see here? Well, notice that if we now divide the users by gender, we get that the males (only one male) downloaded Instagram, while the females downloaded Check Mate Mate. Therefore, we can just add this branch to our tree, to obtain the one in Figure 7.11.
Figure 7.11. Our final decision tree. The prediction goes as follows. The tree makes a prediction as follows: First it checks if the user is young. If they are young, it recommends them Atom Count. If not, then it checks if the user is male or female. If the user is female, it recommends Check Mate Mate, and if the user is male, it recommends them Beehive Finder.
![]()
predict(user): if user is young: recommend Atom Count else: if user is female: recommend Check Mate Mate else: recommend Beehive Finder

This is an excerpt from Manning's book Real-World Machine Learning.
Table 1.1. Use cases for supervised machine learning, organized by the type of problem (view table figure)
Problem
Description
Example use cases
Classification Determine the discrete class to which each individual belongs, based on input data Spam filtering, sentiment analysis, fraud detection, customer ad targeting, churn prediction, support case flagging, content personalization, detection of manufacturing defects, customer segmentation, event discovery, genomics, drug efficacy Regression Predict the real-valued output for each individual, based on input data Stock-market prediction, demand forecasting, price estimation, ad bid optimization, risk management, asset management, weather forecasting, sports prediction Recommendation Predict which alternatives a user would prefer Product recommendation, job recruiting, Netflix Prize, online dating, content recommendation Imputation Infer the values of missing input data Incomplete patient medical records, missing customer data, census data
At first glance, you might imagine you don’t have much to work with. You can count impressions, clicks, and views for users, publishers, and operating systems. Maybe time of day or day of the week has some effect. But on further reflection, you realize that the domains a user visits are features that describe the user, and the users who visit a domain are features of the domain. Suddenly, you have a wealth of data to work with and a real-world opportunity to experience the curse of dimensionality—a phrase used to describe the tribulations of working in high-dimensional space. As you explore the data, you’ll see that a wealth of features can be, if not a curse, a mixed blessing.
You may recognize the logic you’ll apply here as the basis of recommenders, the systems that suggest movies on Netflix, products on Amazon, and restaurants on Yelp. The idea of characterizing users as collections of items, and items as collections of users, is the basis of collaborative filtering, in which users are clustered based on common item preferences, and items are clustered based on the affinities of common users. Of course, the motivation for recommenders is to present users with items they’re likely to purchase. The advertising problem is a variation; instead of many items, the same advertisement is presented in a wide variety of contexts: the publications. The driving principle is that the greatest likelihood of achieving user responses (clicks) will be on publications that are similar to those that have a history of achieving responses. And because similarity is based on common users, pubs chosen in this manner will attract people who are similar in their preferences to past responders.
Listing 10.3. SVD on advertising data
user_idx, pub_idx = {}, {} #1 for i in range(len(users)): user_idx[users[i]] = i for i in range(len(pubs)): pub_idx[pubs[i]] = i nTrainUsers = len(df.user_id.unique()) #2 nTrainPubs = len(df.pub_domain.unique()) V = sp.lil_matrix((nTrainUsers, nTrainPubs)) def matput(imp): if imp.viewed: V[user_idx[imp.user_id], pub_idx[imp.pub_domain]] = 1 df5[df5.click == True].apply(matput, axis=1) # run svds (svd for sparse matrices) u, s, vt = svds(V, k = 1550) plt.plot(s[::-1]) #1 - First substitutes integer indices for user and pub symbolic keys #2 - Creates a sparse matrix of user/pub interactions

This is an excerpt from Manning's book Algorithms of the Intelligent Web, Second Edition.
When a new phone is purchased or a new account is registered with Google, it takes Google Now some time to reach these conclusions. Similarly, if users move to a different home or change jobs, it takes time for Google Now to relearn these locations. The speed at which the model can respond to change is referred to as the learning rate.
In order to display relevant information regarding travel route plans (to make a decision based on an event), we still don’t have enough information. The final piece of the puzzle is predicting when a user is about to leave one location and travel to the other. Similar to our previous application, we could model leaving times and update this over time to reflect changing patterns of behavior. For a given time in the future, it’s now possible to provide a likelihood that a user is in a given location and is about to leave that location in favor of another. If this likelihood triggers a threshold value, Google Now can perform a traffic search and return it to the user as a notification.
Now, let’s examine the code that helped us find the similarity between the users and look closely at how to calculate similarity. The code in the next listing shows the details of the similarity method, which accepts three arguments: the IDs of the two users we wish to compare and the kind of similarity we want to use.
Listing 3.2. Calculating the similarity between two users
def similarity(user_id_a,user_id_b,sim_type=0): user_a_tuple_list = userdict[user_id_a].get_items() user_b_tuple_list = userdict[user_id_b].get_items() common_items=0 sim = 0.0 for t1 in user_a_tuple_list: for t2 in user_b_tuple_list: if (t1[0] == t2[0]): common_items += 1 sim += math.pow(t1[1]-t2[1],2) if common_items>0: sim = math.sqrt(sim/common_items) sim = 1.0 - math.tanh(sim) if sim_type==1: max_common = min(len(user_a_tuple_list),len(user_b_tuple_list)) sim = sim * common_items / max_common print "User Similarity between", å names[user_id_a],"and",names[user_id_b],"is", sim return sim #1 #1 - If no common items, returns zeroWe include two similarity formulas in the code to show that the notion of similarity is fairly flexible and extensible. Let’s examine the basic steps in the calculation of these similarity formulas. First, we take the differences between all the ratings of movies that the users have in common, square them, and add them together. The square root of that value is called the Euclidean distance; and as it stands, it’s not sufficient to provide a measure of similarity:
![]()
We can argue that the RMSE is probably too naïve. Let’s consider two cases. In the first case, we recommend to a user a movie with four stars, and he really doesn’t like it (he’d rate it two stars); in the second case, we recommend a movie with three stars, but the user loves it (he’d rate it five stars). In both cases, the contribution to the RMSE is the same, but it’s likely that the user’s dissatisfaction would probably be larger in the first case than in the second case. You can find the code that calculates the RMSE for our model-based CF solution in the following listing. As we’ve mentioned, other metrics are available, and we’d encourage you to try those also.
We’ve already provided an example of SVD for recommending movies to users, but because of the flexibility of model-based CF it’s equally easy to perform recommendation of users for a given movie: that is, which users we should recommend it to. You could easily imagine such an approach would be useful in the advertising world, should we need to decide which user to promote an item to.
Listing 3.13. Analyzing the ratings of users recommended Star Wars: TPM
> movies_reviewed_by_sw_rec =[get_name_item_reviewed(x[0], user_full,items_full) for x in users_for_star_wars] > movies_flatten = [movie for movie_list in movies_reviewed_by_sw_rec for movie in movie_list] > movie_aggregate = movies_by_category(movies_flatten, 3) > movies_sort = sorted(movie_aggregate,key=lambda x: x[1], reverse=True) > movies_sort [['Drama\n', 64], ['Comedy\n', 38], ['Drama|War\n', 22], ['Drama|Romance\n', 16], ['Action|Sci-Fi\n', 16], ['Action|Adventure|Sci-Fi\n', 14], ['Sci-Fi\n', 14], ['Action|Sci-Fi|Thriller\n', 13], ['Thriller\n', 12], ['Comedy|Romance\n', 12], ['Comedy|Drama\n', 11], ['Action|Drama|War\n', 11], ['Drama|Romance|War\n', 10], ['Drama|Thriller\n', 9], ['Horror|Sci-Fi\n', 9], ['Film-Noir|Thriller\n', 8], ['Western\n', 8], ['Comedy|Sci-Fi\n', 8], ['Drama|Sci-Fi\n', 7]...We first get the movies rated by those in the recommended user set, before flattening this list. We need to flatten the list from a list of lists (where each entry contains the list of rated movies for that user) to a list containing all the ratings of the users together. The method movies_by_category builds a list that contains the genres of the films with a count giving the number of times the movie was rated in the set of users under consideration. The parameter to this method allows the movies to be filtered based on the value of their rating, so in this case we count only movies that have received a rating of 3 or higher. Finally, we sort the output list so that the genres with the largest number of films appear first.
Essentially, what we’ve done is to build a list of genres ranked most positively by the set of users to whom we’re going to recommend The Phantom Menace. Figure 3.5 presents this output in a graphical form.

This is an excerpt from Manning's book Mahout in Action.
Yahoo! Mail decides whether or not incoming messages are spam based on prior emails and spam reports from users, as well as on characteristics of the email itself. A few messages classified as spam are shown in figure 1.4.
The outer loop simply considers every known item (that the user hasn’t already expressed a preference for) as a candidate for recommendation. The inner loop looks to any other user who has expressed a preference for this candidate item, and sees what their preference value for it was. In the end, the values are averaged to come up with an estimate—a weighted average, that is. Each preference value is weighted in the average by how similar that user is to the target user. The more similar a user, the more heavily their preference value is weighted.
This concept, widely used in statistics, can be applied to users to measure their similarity. It measures the tendency of two users’ preference values to move together—to be relatively high, or relatively low, on the same items. For an example, let’s look again at the first sample data file we considered, intro.csv, as follows.
Listing 4.4. A simple recommender input file
1,101,5.0 1,102,3.0 1,103,2.5 2,101,2.0 2,102,2.5 2,103,5.0 2,104,2.0 3,101,2.5 3,104,4.0 3,105,4.5 3,107,5.0 4,101,5.0 4,103,3.0 4,104,4.5 4,106,4.0 5,101,4.0 5,102,3.0 5,103,2.0 5,104,4.0 5,105,3.5 5,106,4.0We noted that users 1 and 5 seem similar because their preferences seem to run together. On items 101, 102, and 103, they roughly agree: 101 is the best, 102 somewhat less good, and 103 isn’t desirable. By the same reasoning, users 1 and 2 aren’t so similar. Note that our reasoning about user 1 can’t really include items 104 through 106, because user 1’s preferences for 104 through 106 aren’t known. The similarity computation can only operate on items that both users have expressed a preference for. (In section 4.3.9, we’ll look at what happens when missing preference values like this are inferred.)
PearsonCorrelationSimilarity still works here because it also implements the ItemSimilarity interface, which is entirely analogous to the UserSimilarity interface. It implements the same notion of similarity, based on the Pearson correlation, but between items instead of users. That is, it compares series of preferences expressed by many users, for one item, rather than by one user for many items.
GenericItemBasedRecommender is simpler. It only needs a DataModel and ItemSimilarity—there’s no ItemNeighborhood. You might wonder at the apparent asymmetry. Recall that the item-based recommendation process already begins with a limited number of starting points: the items that the user in question already expresses a preference for. This is analogous to the neighborhood of similar users that the user-based approach first identifies. It doesn’t make sense in the second half of the algorithm to compute neighborhoods around each of the user’s preferred items.
You’re invited to experiment with different similarity metrics, as we did for users. Not all of the implementations of UserSimilarity also implement ItemSimilarity. You already know how to evaluate the accuracy of this item-based recommender when using various similarity metrics on the now-familiar GroupLens data set. The results are reproduced for convenience in table 4.6.
Table 4.6. Evaluation results under various ItemSimilarity metrics
Implementation
Similarity
PearsonCorrelationSimilarity 0.75 PearsonCorrelationSimilarity + weighting 0.75 EuclideanDistanceSimilarity 0.76 EuclideanDistanceSimilarity + weighting 0.78 TanimotoCoefficientSimilarity 0.77 LogLikelihoodSimilarity 0.77 One thing you may notice is that this recommender setup runs significantly faster. That’s not surprising, given that the data set has about 70,000 users and 10,000 items. Item-based recommenders are generally faster when there are fewer items than users. You may, as a result, wish to increase the percentage of data used in the evaluation to 20 percent or so (pass 0.2 as the final argument to evaluate()). This should result in a more reliable evaluation. Note that there’s little apparent difference among these implementations on this data set.

This is an excerpt from Manning's book Collective Intelligence in Action.
In their first iteration, they launched an application where users—mainly friends and family—could buy items and view relevant articles. There wasn’t much in terms of personalization or user interaction or intelligence—a plain vanilla system.
Next, they added the feature of showing a list of top items purchased by users, along with a list of recently purchased items. This is perhaps the simplest form of applying collective intelligence—providing information in aggregate to users. To grow the application virally, they also enabled users to email these lists to others. Users used this to forward interesting lists of items to their friends, who in turn became users of the application.
In their next iteration, they wanted to learn more about their users. So they built a basic user profile mechanism that contained explicit and implicit profile information. The explicit information was provided directly by the users as part of their accounts—first name, age, and so on. The implicit information was collected from the user interaction data—this included information such as the articles and content users viewed and the products they purchased. They also wanted to show more relevant articles and content to each user, so they built a content-based recommendation engine that analyzed the content of articles—keywords, word frequency, location, and so forth to correlate articles with each other and recommend possibly interesting articles to each user.
Next, they allowed users to generate content. They gave users the ability to write about their experiences with the products, in essence writing reviews and creating their list of recommendations through both explicit ratings of individual products and a “my top 10 favorite products” list. They also gave users the capability to rate items and rate reviews. Ratings and reviews have been shown to influence other users, and numerical rating information is also useful as an input to a collaborative-based recommendation engine.
With the growing list of content and products available on the site, John and Jane now found it too cumbersome and expensive to manually maintain the classification of content on their site. The users also provided feedback that content navigation menus were too rigid. So they introduced dynamic navigation via a tag cloud—navigation built by an alphabetical listing of terms, where font size correlates with importance or number of occurrences of a tag. The terms were automatically extracted from the content by analyzing the content. The application analyzed each user’s interaction and provided users with a personalized set of tags for navigating the site. The set of tags changed as the type of content visited by the users changed. Further, the content displayed when a user clicked on a tag varied from user to user and changed over time. Some tags pulled the data from a search engine, while others from the recommendation engine and external catalogs.
In the next release, they allowed the users to explicitly tag items by adding free text labels, along with saving or bookmarking items of interest. As users started tagging items, John and Jane found that there was a rich set of information that could be derived. First of all, users were providing new terms for the content that made sense to them—in essence they built folksonomies.[4] The tag cloud navigation now had both machine-generated and user-generated tags. The process of extracting tags using an automated algorithm could also be enhanced using the dictionary of tags built by the users. These user-added tags were also useful for finding keywords used by an ad-generation engine. They could also use the tags created by users to connect users with each other and with other items of interest. This is collective intelligence in action.
4 Folksonomies are classifications created through the process of users tagging items.
Next, they allowed their users to generate content. Users could now blog about their experiences, or ask and respond to questions on message boards, or participate in building the application itself by contributing to wikis. John and Jane quickly built an algorithm that could extract tags from the unstructured content. They then matched the interests of users—gained from analyzing their interaction in the applications—with those of other users to find relevant items. They were soon able to learn enough about their users to personalize the site for each user, and to provide relevant content—targeting niche items to niche users. They could also target relevant advertisements based on the user profile and context of interaction.
In its most basic form, people may tag things so as to organize items of interest and remember them. For example, if you have a large number of files on your computer, you normally create folders to organize your files. Tagging is similar—you create categories or buckets and associate them with the item of interest. An item can be tagged with multiple labels, as shown in figure 3.3, a screenshot from Amazon.com, where users are allowed to add multiple tags to an item. By tagging items, users can use tags that make sense to them and don’t have to use the classification of the content owner or site.
Users also tag items so that they can share the information with others, find related items that others have tagged in the same category, and also when they want to be found by others (mainly in social-networking sites).
As shown in figure 3.3, let’s assume that a user is interested in management and has placed a management tag for his items of interest. Over a period of time, if the user would like to see all items related to management, he can look at all items that have been tagged with management. Tags help users organize and find items of interest.
Another feature that’s actively used, especially for social networking applications, is allowing users to explore tags. In our example, any user would be able to click on the management link and see other items that have been tagged by other users with the same tag. This helps them discover new items of interest. User can also look at which users have used the same tag, thus helping them find other users with similar interests.
Listing 8.28. Tag listing for our example
Analyzing the title .... [collective, collect] [intelligence, intellig] [ci, ci] [collective intelligence, collect intellig] [web2.0, web2.0] Analyzing the body .... [web2.0, web2.0] [about, about] [connecting, connect] [users, user] [users, user] [inviting, invit] [users, user] [participate, particip] [applying, appli] [collective, collect] [intelligence, intellig] [ci, ci] [collective intelligence, collect intellig] [improve, improv] [application, applic] [collective, collect] [intelligence, intellig] [ci, ci] [collective intelligence, collect intellig] [enhances, enhanc] [users, user] [experience, experi]