concept item in category machine learning

This is an excerpt from Manning's book Human-in-the-Loop Machine Learning.
Diversity Sampling is a strategy for identifying unlabeled items that are unknown to the Machine Learning model in its current state. This will typically mean items that contain combinations of feature values that are rare or unseen in the training data. The goal of diversity sampling is to target these new, unusual or outlier items for more labels in order to give the Machine Learning algorithm a more complete picture of the problem space.
Figure 4.1 Diversity Sampling, showing items selected to be labeled that are maximally different from the existing training items and from each other. You want to sample items that are not like the items that are currently in your training data and are also not like each other.
![]()
Figure 4.2: Two neural architectures and how you can interpret them for outlier detection. In the top example, you can use the model scores (known as z or logits), which still retain their absolute values before they are normalized via softmax. In the bottom example, you have lost the absolute values in the final layer because of the softmax function, so instead you can use the activation in the 2nd-to-last layer to determine whether an item is an outlier.
![]()
![]()
def get_validation_rankings(self, model, validation_data, feature_method): """Get model outliers from unlabeled data Keyword arguments: model -- current Machine Learning model for this task unlabeled_data -- data that does not yet have a label validation_data -- held out data drawn from the same distribution as the training data feature_method -- the method to create features from the raw text number -- number of items to sample limit -- sample from only this many items for faster sampling (-1 = no limit) An outlier is defined as unlabeled_data with the lowest average from rank order of logits where rank order is defined by validation data inference """ validation_rankings = [] # 2D array, every neuron by ordered list of output on validation data per neuron # Get per-neuron scores from validation data if self.verbose: print("Getting neuron activation scores from validation data") with torch.no_grad(): v=0 for item in validation_data: textid = item[0] text = item[1] feature_vector = feature_method(text) hidden, logits, log_probs = model(feature_vector, return_all_layers=True) #A neuron_outputs = logits.data.tolist()[0] #logits # initialize array if we haven't yet if len(validation_rankings) == 0: for output in neuron_outputs: validation_rankings.append([0.0] * len(validation_data)) n=0 for output in neuron_outputs: validation_rankings[n][v] = output #B n += 1 v += 1 # Rank-order the validation scores v=0 for validation in validation_rankings: validation.sort() #C validation_rankings[v] = validation v += 1 return validation_rankings

This is an excerpt from Manning's book Algorithms of the Intelligent Web, Second Edition.
Let’s imagine that our algorithms have an internal mechanism that’s used to adjust their behavior. We can imagine this as some sort of threshold, or knob, that adjusts the sensitivity of the algorithm. As we twist the knob to zero, the algorithm might be extremely desensitized and classify everything as false (TNR=1, TPR=0). Conversely, if we crank the knob all the way up to 11, the algorithm may classify everything as true (TNR=0, TPR=1). Clearly, neither of these options is desirable. Ideally, we’d like a classifier that returns true if and only if an item is true and false if and only if the item is false (TNR=1, TPR=1). This idealized classifier is unlikely for anything other than a toy problem, but we can look at how our classifier behaves as we twist this knob and use this to evaluate our algorithm; see figure 1.6.
Let’s take some data and start exploring these concepts in detail. In the following sections, we’ll work with items, users, and ratings. In the context of recommendation engines, similarity is a measure that allows you to compare the proximity of two items in much the same way that the physical distance between two cities tells you how close they are to each other geographically. Distance and similarity differ only by the frame of reference or the coordinate space used. Consider that two cities may be geographically similar in that their distance in physical space is low, but culturally they may be very different, in that their distance as a measure of the interests and habits of the general population is very high. In general, the same distance calculation may be performed over different spaces to gain different measures of similarity.
For two cities, you’d use their longitude and latitude coordinates to calculate their geographical proximity. Think of the ratings as the coordinates in the space of items or users. Let’s look at these concepts in action. We’ll select three users and associate with them a list of movies (items) and their hypothetical rankings. As is typically the case, ratings will range between 1 and 5 (inclusive). The assignments for the first two users (Frank and Constantine) involve ratings that are either 4 or 5—these people really like all the movies we selected. But the third user’s ratings (Catherine’s) are between 1 and 3. So clearly, we expect the first two users to be similar to each other and be dissimilar to the third user. When we load the example data in the script, we have available the users, movies, and ratings shown in table 3.1.
Listing 3.7. RatingCountMatrix class
class RatingCountMatrix: user_id_a = None user_id_b = None matrix = None def __init__(self, user_id_a, user_id_b): num_rating_values = max([x[0] for x in data]) self.user_id_a = user_id_a self.user_id_b = user_id_b self.matrix = np.empty((num_rating_values,num_rating_values,)) self.matrix[:] = 0 self.calculate_matrix(user_id_a,user_id_b) def get_shape(self): a = self.matrix.shape return a def get_matrix(self): return self.matrix def calculate_matrix(self,user_id_a, user_id_b): for item in items_reviewed(user_id_a, userdict): if int(item) in items_reviewed(user_id_b, userdict): i = get_score_item_reviewed(user_id_a,item, userdict)-1 j = get_score_item_reviewed(user_id_b,item, userdict)-1 self.matrix[i][j] +=1 def get_total_count(self): return self.matrix.sum() def get_agreement_count(self): return np.trace(self.matrix) #sum across the diagonal

This is an excerpt from Manning's book Mahout in Action.
Classification techniques decide how much a thing is or isn’t part of some type or category, or how much it does or doesn’t have some attribute. Classification, like clustering, is ubiquitous, but it’s even more behind the scenes. Often these systems learn by reviewing many instances of items in the categories in order to deduce classification rules. This general idea has many applications:
The third line shows how it’s based on item-item similarities, not user-user similarities as before. The algorithms are similar, but not entirely symmetric. They do have notably different properties. For instance, the running time of an item-based recommender scales up as the number of items increases, whereas a user-based recommender’s running time goes up as the number of users increases.
This suggests one reason that you might choose an item-based recommender: if the number of items is relatively low compared to the number of users, the performance advantage could be significant.
Also, items are typically less subject to change than users. When items are things like DVDs, it’s reasonable to expect that over time, as you acquire more data, estimates of the similarities between items converge. There is no reason to expect them to change radically or frequently. Some of the same may be said of users, but users can change over time and new knowledge of users is likely to come in bursts of new information that must be digested quickly. To connect this to the last example, it’s likely that Bowling In Hades albums and Rock Mobster albums will remain as similar to each other next year as today. But it’s a lot less likely that the same fans mentioned above will have the same tastes next year, and so their similarities will change more.
KnnItemBasedRecommender still estimates preference values by means of a weighted average of the items the user already has a preference for, but the weights aren’t the results of a similarity metric. Instead, the algorithm calculates the optimal set of weights to use between all pairs of items by means of some linear algebra—here’s where the linear interpolation comes in. Yes, it’s possible to optimize the weights with some mathematical wizardry.
In reality, it would be very expensive to compute this across all pairs of items, so instead it first calculates a neighborhood of items most similar to the target item—the item for which a preference is being estimated. It chooses the n nearest neighbors, in much the same way that NearestNUserNeighborhood did. One can try KnnItemBasedRecommender as shown in the following listing.
Listing 4.9. Deploying KnnItemBasedRecommender
ItemSimilarity similarity = new LogLikelihoodSimilarity(model); Optimizer optimizer = new NonNegativeQuadraticOptimizer(); return new KnnItemBasedRecommender(model, similarity, optimizer, 10);This code will cause the recommender to use a log-likelihood similarity metric to calculate nearest-10 neighborhoods of items. Then it’ll use a quadratic programming–based strategy to calculate the linear interpolation. The details of this calculation are outside the scope of the book.
The slope-one name comes from the fact that the recommender algorithm starts with the assumption that there’s some linear relationship between the preference values for one item and another, that it’s valid to estimate the preferences for some item Y based on the preferences for item X, via some linear function like Y = mX + b. Then the slope-one recommender makes the additional simplifying assumption that m = 1: slope one. It just remains to find b = Y - X, the (average) difference in preference value, for every pair of items.

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.
An alternative to manual categorization and rigid menus is to build a system that can learn about each user—what kind of content she’s interested in—and dynamically build navigation links, hyperlinks to other relevant items, whose text or phrases are also familiar to the user. Further, such a system can be built in a cost-effective manner without having to rely on professional editors to categorize items.
Users tagging items—adding keywords or phrases to items—is now ubiquitous on the web. This simple process of a user adding labels or tags to items, bookmarking items, sharing items, or simply viewing items provides a rich dataset that can translate into intelligence, for both the user and the items. This intelligence can be in the form of finding items related to the one tagged; connecting with other users who have similarly tagged items; or drawing the user to discover alternate tags that have been associated with an item of interest and through that finding other related items.
In this chapter, we look at three forms of generating tags in your application: professionally generated tags, user-generated tags, and machine-generated tags. We review the advantages and disadvantages of each approach and develop guidelines for creating tags. We briefly review how you can use dynamic navigation in your application. We use a working example to illustrate the process of developing the term vector or metadata for the item and user. Next, we discuss how you can build this infrastructure in a scalable manner. For this, we first review the various designs used to persist tagging-related data and develop the recommended persistence architecture. Next, we develop code to build a tag cloud, one of the ways to add dynamic navigation to your application, and end with some practical issues.
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.
Tags provide a common vocabulary to represent metadata associated with users and items. The metadata developed can be again divided into content-based metadata and collaborative-based metadata.
In the content-based approach, metadata associated with the item is developed by analyzing the item’s content as explained in section 2.2.3. This is represented by a term vector, a set of tags with their relative weights. Similarly, metadata can be associated with the user by aggregating the metadata of all the items visited by the user within a window of time, as explained in section 2.4.2.
In the collaborative approach, user actions are used for deriving metadata. User tagging is an example of such an approach, and we illustrated with the example in section 2.2. Basically, the metadata associated with the item can be computed by computing the term vector from the tags—taking the relative frequency of the tags associated with the item and normalizing the counts.
When you think about metadata for a user and item using tags, think about a term vector with tags and their related weights.