concept dataset in category machine learning

appears as: dataset, datasets, The dataset, dataset, datasets, A dataset, A dataset
Machine Learning with TensorFlow, Second Edition

This is an excerpt from Manning's book Machine Learning with TensorFlow, Second Edition.

Suppose you’re trying to bake desserts in an oven. If you’re new to the kitchen, it can take days to come up with both the right combination and perfect ratio of ingredients to make something that tastes great. By recording recipes, you can remember how to quickly repeat the dessert if you happen to discover the ultimate tasty meal.

Listing 7.3 Obtaining a dataset for k-means
import tensorflow as tf
import numpy as np
from bregman.suite import *
 
 
filenames = tf.train.match_filenames_once('./audio_dataset/*.wav')
count_num_files = tf.size(filenames)
filename_queue = tf.train.string_input_producer(filenames)
reader = tf.WholeFileReader()
filename, file_contents = reader.read(filename_queue)
 
chroma = tf.placeholder(tf.float32)       #A
max_freqs = tf.argmax(chroma, 0)          #A
 
def get_next_chromagram(sess):
    audio_file = sess.run(filename)
    F = Chromagram(audio_file, nfft=16384, wfft=8192, nhop=2205)
    return F.X
 
def extract_feature_vector(sess, chroma_data):                   #B
    num_features, num_samples = np.shape(chroma_data)
    freq_vals = sess.run(max_freqs, feed_dict={chroma: chroma_data})
    hist, bins = np.histogram(freq_vals, bins=range(num_features + 1))
    return hist.astype(float) / num_samples
 
def get_dataset(sess):                                           #C
    num_files = sess.run(count_num_files)
    coord = tf.train.Coordinator()
    threads = tf.train.start_queue_runners(coord=coord)
    xs = []
    for _ in range(num_files):
        chroma_data = get_next_chromagram(sess)
        x = [extract_feature_vector(sess, chroma_data)]
        x = np.matrix(x)
        if len(xs) == 0:
            xs = x
        else:
            xs = np.vstack((xs, x))
    return xs

8.1           The user activity from walking dataset

The user activity from walking dataset contains 22 participants and their associated Android-based positional data. The data was donated in March 2014, and has been accessed more than 69,000 times. The dataset is formed when the accelerometer in an Android phone positioned in the chest pocket of a participant collects (X, Y, Z, t) positional and time data. These participants simply walked in the wild and performed various activities along a predefined path. The data can be used for unsupervised inference of activity type and has been a frequently used benchmark in the machine learning domain because it provides challenges for identification and authentication of people using motion patterns.

You can download the dataset from https://archive.ics.uci.edu/ml/machine-learning-databases/00286/User%20Identification%20From%20Walking%20Activity.zip. The dataset unzips in to a set of files in a folder structure that looks like the following:

Grokking Machine Learning

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

Unsupervised learning is also a very common type of machine learning. It differs from supervised learning in that the data has no labels. What is a dataset with no labels, you ask? Well, it is a dataset with only features, and no target to predict. For example, if our housing dataset had no prices, then it would be an unlabeled dataset. If our emails dataset had no labels, then it would simply be a dataset of emails, where ‘spam’ and ‘no spam’ is not specified.

Figure 9.14. Plot of the dataset in Table 9.1. Note that it is not separable by a line. Therefore, this dataset is a good candidate for the kernel method.

Ok, we now have all the tools to train an SVM using the rbf kernel. Let’s look again at the example at the beginning of this section. The dataset is in Table 9.6, and the figure in Figure 9.19.

Human-in-the-Loop Machine Learning

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

Every computer science department offers Machine Learning courses, but very few offer courses on how to create training data. At most, there might be one or two lectures about creating training data among hundreds of Machine Learning lectures across half a dozen courses. This is changing, but slowly. For historical reasons, academic Machine Learning researchers have tended to keep the datasets constant, and evaluated their Machine Learning in terms of different algorithms.

  • A sample of data that is the same distribution of as your current batch of data getting annotated. If you are using active learning, then this is a random sample from within your current iteration of active learning. This will allow you to calculate the accuracy of each batch and by extension the accuracy of the dataset as a whole.
  • Figure 8.8: Krippendorff's alpha, calculating the overall level of agreement in a dataset to determine if it is reliable enough to use for training data. The inputs are the white areas: the Annotations (bottom right) and the Label Weights (top middle). Because we have mutually exclusive labels, this simply has each label weighted only with itself, but if we had hierarchical, ordinal or other types of data then we would enter different values as Label Weights. The top row of calculations contains the expected agreement by random chance and the bottom row of calculations calculates the actual agreement in the data. The two are used to calculate the expected agreement (pe) and actual agreement (pa) for the dataset, from which the adjusted overall agreement alpha is calculated.
    Machine Learning Bookcamp

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

    This data may be not good enough, however, for a wide range of reasons. One reason could be that the dataset is too small for us to learn any useful patterns. Another reason could be that the data is too noisy. The users may not use the button correctly, so it will be useless for training a machine learning model, or the data collection process could be broken, collecting only a small fraction of the data we want.

    Suppose that we have a dataset with descriptions of cars, like make, model, and age, and we would like to use machine learning to predict their prices. These characteristics of cars are called features, and the price is the target variable — something we want to predict. Then the model gets the features and combines them to output the price.

    Figure 2.3 The output of the head() function of a Pandas dataframe: it shows the first five rows of the dataset. This output allows us to understand what the data looks like.
    Exploring Machine Learning Basics

    This is an excerpt from Manning's book Exploring Machine Learning Basics.

    If you recall Chapter 1, the framework we learned for making a decision was Remember-Formulate-Predict. This is precisely how supervised learning works. The model first remembers the dataset of dogs and cats, then formulates a model, or a rule for what is a dog and what is a cat, and when a new image comes in, the model makes a prediction about what the label of the image is, namely, is it a dog or a cat.

    Figure 2.3. Supervised learning follows the Remember-Formulate-Predict framework from Chapter 1.

    Now, notice that in Figure 2.1, we have two types of datasets, one in which the labels are numbers (the weight of the animal), and one in which the labels are states, or classes (the type of animal, namely cat or dog). This gives rise to two types of supervised learning models.

    Unsupervised learning is also a very common type of machine learning. It differs from supervised learning in that the data has no labels. What is a dataset with no labels, you ask? Well, it is a dataset with only features, and no target to predict. For example, if our housing dataset had no prices, then it would be an unlabeled dataset. If our emails dataset had no labels, then it would simply be a dataset of emails, where ‘spam’ and ‘no spam’ is not specified.

    Machine Learning with R, the tidyverse, and mlr

    This is an excerpt from Manning's book Machine Learning with R, the tidyverse, and mlr.

    If we measured 1,000 hippo tusks and plotted a histogram of their lengths, we might get something like the distribution shown in figure A.3. The bars of the histogram represent the frequency with which a particular tusk length occurs in the dataset. I’ve overlaid a theoretical normal distribution (the smooth line) over the histogram, whose mean and standard deviation correspond to those of the data.

    Now imagine that I make a more reasonable request and ask you to reorganize and plot a dataset, ready to be passed through a machine learning pipeline. You could use base R functions for this, and they would work fine. But the code would be long, it wouldn’t be very human-readable (so in a month you’d struggle to remember what you did), and the plots would be cumbersome to produce.

    Listing 5.2. Cleaning the dataset
    names(wineTib) <- c("Class", "Alco", "Malic", "Ash", "Alk", "Mag",
                        "Phe", "Flav", "Non_flav", "Proan", "Col", "Hue",
                        "OD", "Prol")
    
    wineTib$Class <- as.factor(wineTib$Class)
    
    wineTib
    
    # A tibble: 178 x 14
       Class  Alco Malic   Ash   Alk   Mag   Phe  Flav Non_flav Proan
       <fct> <dbl> <dbl> <dbl> <dbl> <int> <dbl> <dbl>    <dbl> <dbl>
     1 1      14.2  1.71  2.43  15.6   127  2.8   3.06    0.28   2.29
     2 1      13.2  1.78  2.14  11.2   100  2.65  2.76    0.26   1.28
     3 1      13.2  2.36  2.67  18.6   101  2.8   3.24    0.3    2.81
     4 1      14.4  1.95  2.5   16.8   113  3.85  3.49    0.24   2.18
     5 1      13.2  2.59  2.87  21     118  2.8   2.69    0.39   1.82
     6 1      14.2  1.76  2.45  15.2   112  3.27  3.39    0.34   1.97
     7 1      14.4  1.87  2.45  14.6    96  2.5   2.52    0.3    1.98
     8 1      14.1  2.15  2.61  17.6   121  2.6   2.51    0.31   1.25
     9 1      14.8  1.64  2.17  14      97  2.8   2.98    0.290  1.98
    10 1      13.9  1.35  2.27  16      98  2.98  3.15    0.22   1.85
    # ... with 168 more rows, and 4 more variables: Col <dbl>,
    #   Hue <dbl>, OD <dbl>, Prol <int>
    Figure 18.1. A challenging clustering problem. The dataset shown in each facet contains clusters of varying shapes and diameters, with cases that could be considered noise. The three subplots show the data clustered using DBSCAN, hierarchical clustering (complete linkage), and k-means (Hartigan-Wong). Of the three algorithms used, only DBSCAN is able to faithfully represent these shapes as distinct clusters.
    Machine Learning for Business: Using Amazon SageMaker and Jupyter

    This is an excerpt from Manning's book Machine Learning for Business: Using Amazon SageMaker and Jupyter.

    Figure 1.5. Machine learning functions to identify a group of similar items in a dataset

    Let’s pull a dataset out of figure 1.4 to look at a bigger sample in figure 1.5. You can see that the dataset comprises two types of circles: dark circles and light circles. In figure 1.5, there is a pattern that we can see in the data. There are lots of light circles at the edges of the dataset and lots of dark circles near the middle. This means that our function, which provides the directions on how to separate the dark circles from light circles, will start at the left of the diagram and do a big loop around the dark circles before returning to its starting point.

    Figure 1.5. Machine learning functions to identify a group of similar items in a dataset
    Listing 2.3. Viewing the dataset
    df = pd.read_csv(
        f's3://{data_bucket}/{subfolder}/{dataset}')     #1
    df.head()                                            #2
  • Download the datasets from your S3 bucket.
  • Create a folder in your S3 bucket to store the datasets.
  • Upload the datasets to your AWS S3 bucket.
  • 7.4.4. Downloading the datasets from the S3 bucket

    We stored the datasets for this chapter in one of our S3 buckets. You can download each of the datasets by clicking the following links:

    Machine Learning with TensorFlow

    This is an excerpt from Manning's book Machine Learning with TensorFlow.

    Figure 1.4. The learning approach generally follows a structured recipe. First, the dataset needs to be transformed into a representation, most often a list of features, which can be used by the learning algorithm. The learning algorithm chooses a model and efficiently searches for the model’s parameters.
    Listing 3.4. Splitting the dataset into testing and training sets
    def split_dataset(x_dataset, y_dataset, ratio): 1 arr = np.arange(x_dataset.size) 2 np.random.shuffle(arr) 2 num_train = int(ratio * x_dataset.size) 3 x_train = x_dataset[arr[0:num_train]] 4 x_test = x_dataset[arr[num_train:x_dataset.size]] 4 y_train = y_dataset[arr[0:num_train]] 5 y_test = y_dataset[arr[num_train:x_dataset.size]] 5 return x_train, x_test, y_train, y_test 6

    Image processing is a lively field of research, so datasets are readily available for you to use, instead of using your own limited images. For instance, a dataset called CIFAR-10 contains 60,000 labeled images, each 32 × 32 in size.

    Real-World Machine Learning

    This is an excerpt from Manning's book Real-World Machine Learning.

  • Tuning the model parameters— ML algorithms are configured with parameters specific to the underlying algorithm, and the optimal value of these parameters often depends on the type and structure of the data. The value of each parameter, or any of them combined, can have an impact on the performance of the model. We introduce various ways to find and select the best parameter values, and show how this can help in determining the best algorithm for the dataset in question.
  • Listing 6.3. Converting categorical columns to numerical features
    def cat_to_num(data): #1 categories = unique(data) #1 features = {} #1 for cat in categories: #1 binary = (data == cat) #1 features["%s:%s"%(data.name, cat)] = binary.astype("int") #1 return pandas.DataFrame(features) #1 payment_type_cats = cat_to_num(data['payment_type']) #2 vendor_id_cats = cat_to_num(data['vendor_id']) #2 store_and_fwd_flag_cats = cat_to_num(data['store_and_fwd_flag']) #2 rate_code_cats = cat_to_num(data['rate_code']) #2 data = data.join(payment_type_cats) #3 data = data.join(vendor_id_cats) #3 data = data.join(store_and_fwd_flag_cats) #3 data = data.join(rate_code_cats) #3 #1 - Function for converting a categorical column to a set of numerical columns #2 - Converts four categorical features in the dataset to numerical #3 - Adds the converted data to the full dataset used for training and testing

    As always, you’ll start by investigating and analyzing the dataset at hand to understand the feature and target columns so you can make the best decisions about which feature-extraction and ML algorithms to use. You’ll then build the initial model from the simplest feature-extraction algorithms to see how you can quickly get a useful model with only a few lines of code. Next, you’ll dig a little deeper into the library of feature-extraction and ML modeling algorithms to improve the accuracy of the model even further. You’ll conclude by exploring various deployment and scalability aspects of putting the model into production.

    As you may recall from our discussion of NLP features in the previous chapter, we started out with a simple technique to featurize natural-language data: bag of words. This method analyzes the entire corpus of text, builds a dictionary of all words, and translates every instance in the dataset into a list of numbers, counting how many times each word appears in the document. To refresh your memory, let’s revisit bag of words in figure 8.2.

    Figure 8.2. The bag-of-words vectorization algorithm. From a dictionary of words, you can transform any new document (for example, Text 1, Text 2 in the figure) into a list of numbers that counts how many times each word appears in the document.

    In listing 8.1, you load the dataset, create a 70%–30% train-test split, and use a simple word-count method for extracting features. An important point to realize in this process is that you can’t contaminate the bag-of-words dictionary with words from the test set. This is why you split the dataset into training and testing subsets before you build the vectorizer dictionary—to get a realistic estimate of the accuracy of the model on previously unseen data.

    8.1.1. A first glance at the dataset

    Our dataset consists of written movie reviews from the Internet Movie Database, IMDb (www.imdb.com). The training data consists of 50,000 reviews, selected so that each movie has no more than 30 reviews in the dataset. For each review, the outcome variable is encoded as a binary feature, with the value 1 if the manual IMDb rating for that review is greater than 6, and the value 0 if the rating is less than 5. No reviews in the intermediate ratings of 5–6 are included in the dataset.

    Algorithms of the Intelligent Web, Second Edition

    This is an excerpt from Manning's book Algorithms of the Intelligent Web, Second Edition.

    You may ask, “How is this different from ML, which is also about prediction?” This is a good question! In general, ML techniques focus on understanding and generalizing the underlying structure and relationships of a dataset, whereas predictive analytics is often about scoring, ranking, and making predictions about future data items and trends, frequently in a business or operational setting. Although this may appear to be a somewhat fuzzy comparison, there’s a large degree of overlap among the intelligent-algorithm classes we’ve introduced, and these categories aren’t concrete and definite.

    Listing 2.1. Interrogating the Iris dataset in scikit-learn (interactive shell)
    >>> import numpy as np >>> from sklearn import datasets #1 >>> >>> iris = datasets.load_iris() #2 >>> np.array(zip(iris.data,iris.target))[0:10] #3 array([[array([ 5.1, 3.5, 1.4, 0.2]), 0], #4 [array([ 4.9, 3. , 1.4, 0.2]), 0], [array([ 4.7, 3.2, 1.3, 0.2]), 0], [array([ 4.6, 3.1, 1.5, 0.2]), 0], [array([ 5. , 3.6, 1.4, 0.2]), 0], [array([ 5.4, 3.9, 1.7, 0.4]), 0], [array([ 4.6, 3.4, 1.4, 0.3]), 0], [array([ 5. , 3.4, 1.5, 0.2]), 0], [array([ 4.4, 2.9, 1.4, 0.2]), 0], [array([ 4.9, 3.1, 1.5, 0.1]), 0]], dtype=object) #1 - Imports scikit-learn datasets #2 - Loads in the Iris dataset #3 - Creates an array of both the data and the target, and displays the first 10 lines #4 - Contents of the first 10 rows of the array displayed
    Figure 2.3. A number line containing two possible clusters in a single dimension. An entry indicates the existence of that number in the dataset. Data points represented by the same shape indicate one possible intuitive clustering of the data.

    You generate a new, down-sampled dataset in the following way. First, you keep all ad impressions that resulted in a click. These precious data points can’t be down-sampled, but because they represent only a small fraction of all impressions shown (an industry average click-through rate is much less than 1%), you don’t need to. Instead, you can heavily down-sample the impressions that didn’t lead to a click, leaving a dataset of a much more manageable size. This also has the effect of rebalancing your dataset. So, instead of having a very large dataset with very few positive impressions (which few classification or regression techniques will manage well), you now have a much more balanced dataset in which the positive instances represent a larger proportion of the total. We’ll discuss the importance of balancing your dataset further in section 5.5.2.

    To balance and shuffle our dataset for training, we’ll continue to work at the command line. The next listing provides the command to extract, shuffle, and create the dataset.

    Collective Intelligence in Action

    This is an excerpt from Manning's book Collective Intelligence in Action.

    Collective intelligence is the heart of Web 2.0 applications. It’s generally acknowledged that one of the core components of Web 3.0 applications will be the use of artificial intelligence.[6] There’s debate as to whether this intelligence will be attained by computers reasoning like humans or by sites leveraging the collective intelligence of humans using techniques such as collaborative filtering. Either way, having the dataset generated from real human interactions will be necessary and useful.

    There are two steps involved with using predictive models: the learning phase and the application phase. In the learning phase, given a dataset of examples where each example has a set of input and output attributes, the learning process tries to build a mathematical model that predicts the output attribute value based on the input values. Once a mathematical model has been built, the second step is to apply the model to make predictions. The application of the mathematical model for predictions is typically fast, and can be used for real-time predictions in an application, while the amount of time taken to build the predictive model is much greater and is typically done asynchronously in the application.

  • Each term vector gets converted into the WEKA Instance object. A collection of these Instance objects forms the dataset and is represented by the Instances object.
  • Listing 10.2 shows the first part of the code for WEKAPredictiveBlogDataSetCreatorImpl, which deals with creating the dataset with positive and negative test cases.

    Listing 10.2. Retrieving blogs

    To create the dataset, we specify a set of positive and negative test cases. For example, in the code