Basics of machine learning

Author(s) Anup Kumar avatar Anup Kumar
Reviewers Björn Grüning avatar Saskia Hiltemann avatar Bérénice Batut avatar Helena Rasche avatar Gildas Le Corguillé avatar Anup Kumar avatar
Overview
Creative Commons License: CC-BY Questions:
  • What is machine learning?

  • Why is it useful?

  • What are its different approaches?

Objectives:
  • Provide the basics of machine learning and its variants.

  • Learn how to do classification using the training and test data.

  • Learn how to use Galaxy’s machine learning tools.

Requirements:
Time estimation: 30 minutes
Supporting Materials:
Published: Nov 5, 2018
Last modification: Mar 5, 2024
License: Tutorial Content is licensed under Creative Commons Attribution 4.0 International License. The GTN Framework is licensed under MIT
purl PURL: https://gxy.io/GTN:T00270
rating Rating: 5.0 (1 recent ratings, 12 all time)
version Revision: 13

Machine learning uses techniques from statistics, mathematics and computer science to make computer programs learn from data. It is one of the most popular fields of computer science and finds applications in multiple streams of data analysis such as classification, regression, clustering, dimensionality reduction, density estimation and many more. Some real-life applications are spam filtering, medical diagnosis, autonomous driving, recommendation systems, facial recognition, stock prices prediction and many more. The following image shows a basic flow of any machine learning task. Data is provided by a user to a machine learning algorithm for analysis.

data. Open image in new tab

Figure 1: Flow of a machine learning task.

There are multiple ways in which machine learning can be used to perform data analysis. They depend on the nature of data and the kind of data analysis. The following image shows the most popular ones. In supervised learning techniques, the categories of data records are known beforehand. But in unsupervised learning, the categories of data records are not known.

data. Open image in new tab

Figure 2: Different types of machine learning.

In general, machine learning can be used in multiple real-life tasks by applying its variants as depicted in the following image.

data. Open image in new tab

Figure 3: Real-life usage of machine learning.

The following image shows how a classification task is performed. The complete data is divided into training and test sets. The training set is used by a classifier to learn features. It results in a trained model and its robustness (of learning) is evaluated using the test set (unseen by the classifier during the training).

data. Open image in new tab

Figure 4: Supervised learning.

This tutorial shows how to use a machine learning module implemented as a Galaxy tool. The data used in this tutorial is available at Zenodo.

Agenda

Performing a machine learning task (classification) using a tool involves the following steps:

  1. Data upload
  2. Train a classifier
  3. Predict using a trained model
  4. See predictions

Data upload

The datasets required for this tutorial contain 9 features of breast cells which include the thickness of clump, cell-size, cell-shape and so on (more information). In addition to these features, the training dataset contains one more column as target. It has a binary value (0 or 1) for each row. 0 indicates no breast cancer and 1 indicates breast cancer. The test dataset does not contain the target column.

Hands-on: Data upload
  1. Create a new history for this tutorial.

    To create a new history simply click the new-history icon at the top of the history panel:

    UI for creating new history

  2. Import the following datasets and choose the type of data as tabular.

    https://zenodo.org/record/1401230/files/breast-w_train.tsv
    https://zenodo.org/record/1401230/files/breast-w_test.tsv
    
    • Copy the link location
    • Click galaxy-upload Upload Data at the top of the tool panel

    • Select galaxy-wf-edit Paste/Fetch Data
    • Paste the link(s) into the text field

    • Press Start

    • Close the window

  3. Rename datasets to breast-w_train and breast-w_test.

    • Click on the galaxy-pencil pencil icon for the dataset to edit its attributes
    • In the central panel, change the Name field
    • Click the Save button

  4. The datasets should look like these:

    data. Open image in new tab

    Figure 5: Training data (breast-w_train) with targets (9 features and one target).
    data. Open image in new tab

    Figure 6: Test data (breast-w_test) (9 features and no target).

Train a classifier

In this step, we will use the SVM (support vector machine) classifier for training on the breast-w_train dataset. The classifier learns a mapping between each row and its category. SVM is a memory efficient classifier which needs only those data points which lie on the decision boundaries among different classes to predict a class for a new sample. The rest of the data points can be thrown away. We will use the LinearSVC variant of SVM which is faster. Other variants SVC and NuSVC have high running time for large datasets. The last column of the training dataset contains a category/class for each row. The classifier learns a mapping between data row and its category which is called a trained model. The trained model is used to predict the categories of the unseen data.

Hands-on: Train a classifier

Support vector machines (SVMs) for classification ( Galaxy version 1.0.8.1) with the following parameters to train:

  • “Select a Classification Task”: Train a model
    • “Classifier type”: Linear Support Vector Classification
    • “Select input type”: tabular data
    • param-file “Training samples dataset”: breast-w_train tabular file
    • “Does the dataset contain header”: Yes
    • “Choose how to select data by column”: All columns EXCLUDING some by column header name(s)
    • “Type header name(s)”: target
    • param-file “Dataset containing class labels or target values”: breast-w_train tabular file
    • “Does the dataset contain header”: Yes
    • “Choose how to select data by column”: Select columns by column header name(s)
    • “Type header name(s):”: target

Predict using a trained model

The previous step produced a trained model (a zip archive) which we will now use to predict classes for the test data (breast-w_test).

Hands-on: Predict using a trained model

Support vector machines (SVMs) for classification ( Galaxy version 1.0.8.1) with the following parameters:

  • “Select a Classification Task”: Load a model and predict
    • param-file “Models”: the zip dataset produced by Support vector machines (SVMs) for classification tool
    • param-file “Data (tabular)”: breast-w_test file
    • “Does the dataset contain header”: Yes
    • “Select the type of prediction”: Predict class labels

See predictions

The last column of the predicted dataset shows the category of each row. A row either got 0 (no breast cancer) or 1 (breast cancer) as its predicted category.

Hands-on: See the predicted column
  1. Click on the galaxy-eye (eye) icon of the dataset created by the previous step.
  2. The last column of the table shows the predicted category (target) for each row.

Read more about machine learning using scikit-learn.