concept sample in category machine learning

appears as: sample, samples, sample, samples, The sample
Human-in-the-Loop Machine Learning

This is an excerpt from Manning's book Human-in-the-Loop Machine Learning.

While Active Learning can be self-correcting, can you see any evidence where it didn’t self-correct some bias? Common examples would be over sampling extra long or extra short sentences. The Computer Vision equivalent would be over sampling images that are extra large/small or hi/low resolution. Your choice of outlier strategy and Machine Learning model might over sample based on features like this which are not core to your goal. You might consider applying the methods in this chapter to different buckets of data, in that case: lowest confident short sentences, lowest confident medium sentences, and lowest confident long sentences.

Figure 3.6: showing how Uncertainty Sampling as an Active Learning strategy, which over-samples unlabeled items that are closer to the decision boundary (and sometimes to each other), and are therefore more likely to get a human label that results in a change in that decision boundary.
  • Representative Sampling. Finding a sample of unlabeled items that look most like your target domain, compared to your training data. In our example, let’s imagine that people mostly used your voice-assistant to request songs. Representative Sampling would therefore target examples of song requests over other types of commands.
  • 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  
     
    How Machine Learning Works

    This is an excerpt from Manning's book How Machine Learning Works.

    To start with anything, we first need a sample of people (both diabetics and non-diabetics) with their BG and BMI recorded. The sample we're going to work with here is the sample recorded in the Pima Indians Diabetes Dataset.

    From that definition, because all the members of a population share common properties, it's reasonable to assume that our findings on an unbiased sample selected from these members is representative of the population. In an unbiased sample, we don't see any favoring toward specific features in the data. For example, the sample in Figure 1.2(a) is a biased sample, as it contains only overweight diabetics and normal-weight non-diabetics.

    Figure 2.2: (a) A sample biased towards overweight diabetics and normal-weight non-diabetics. (b) An unbiased sample with no favoring regarding weight.

    If our sample includes only the overweight diabetics and the normal non-diabetics, then the game is obviously rigged! From such a sample, any model we use will predict “diabetic” for anyone whose BMI value is high. We cannot consider such a conclusion to be representative of the population. That's why only an unbiased sample can be representative of the original population, such as a sample constructed by randomly choosing diabetics and non-diabetics regardless of their BMI values, like the one we see in Figure 1.2(b).

    As we can see in the output of the previous code snippet, the mean values are: 120.89, 31.99, and 0.35 for the BG, BMI, and Class respectively. From this description, we can say that the values of BMI for the examples in the sample tend to be around the value of 31.99. The same can be said about BG. However, it's not very clear what we'd mean if we said that the Class of the members (being diabetics or non-diabetics) is centered around 0.35. This field of data can only take one of two values, 0 or 1. How can its average be a real number?

    In the context of understanding the central tendency of a sample of discrete values like the examples' Class, the mean is not a very suitable measure. So, instead, two other measures can be used to give more meaningful information about the central tendency in that case. The first one is the mode, which is simply the most frequent value across the sample. This captures similar information to the mean but for discrete values, in the sense that what tends to be the most common in a group is the average setting within the group. pandas also provides us with the mode() method in order to calculate the mode of the values across the columns of a DataFrame.

    mode_values = data_of_interest.mode() print(mode_values)

    We can see now that the mode of the Class field is 0, meaning that the most common members in the sample are non-diabetics. And as we can see, the mode can also be calculated for continuous data like the BMI; and in the case here, its value is close to the mean value (32 and 31.99). Another thing to notice is that the BG has two mode values, 99 and 100, unlike the other fields, which have only one mode. This happens because the 99 and 100 BG values are the two most common values in the set, and they happen to occur the same number of times

    The remaining central tendency measure that we can use with discrete data is the median, which is simply the value that splits the sample into two halves: a lower one and a higher one. The median is the measure most related to the concept of “center,” as it's basically the value at the center of the values, which gives a sense of where the other values hang around. While calculating the median of sample is only a matter of sorting the values and reporting the value in the middle, pandas provides with a median() method as well to alleviate the task of having to writing something specifically to carry out this process.

    median_values = data_of_interest.median() print(median_values)

    We can see from the output that the median and the mode agree for the Class field, both being 0. However, the median would be more informative when working with discrete data that have more than two possible values, as it gives a clearer view of a center compared to the case with Class, which here has only two possible values. We can also see that like the mode, the median is close to the mean values of the BMI, but that's not the case for the Blood Glucose. This kind of discrepancy between the central tendency measures calls into question the distribution of the data itself, which is responsible of whether these measures align or not. The first step in understanding how the values of a sample are distributed is to understand how the these values vary from their central tendencies, which is provided by another set of descriptive statistics called measures of dispersion.