WOLFRAM NOTEBOOK

Introduction to Machine Learning

Examples of Machine Learning

Let’s look at some examples of Machine Learning.
It can be used to answer questions as follows:

What language is this?

LanguageIdentify takes pieces of text, and identifies what human language they’re in.
Identify the language each phrase is in:
In[]:=
LanguageIdentify"thank you","merci","dar las gracias","","Дякую","ன்றி"
Out[]=
English
,
French
,
Spanish
,
Korean
,
Ukrainian
,
Tamil

What’s in this image?

Identify what an image is of:
In[]:=
ImageIdentify
Out[]=
cheetah

What sort of sentiment does this text express?

Classifying the “sentiment” of text:
In[]:=
Classify["Sentiment","I'm so excited to be programming"]
Out[]=
Positive
In[]:=
Classify["Sentiment","I am really late for class!"]
Out[]=
Positive

The Machine is trying to answer a Question: Is this A or B (or C or D or E)

  • Is this English or French (or Arabic or Hindi)?
  • Is this a cheetah or a tiger or an owl?
  • Is this an example of positive or negative or neutral sentiment?
  • Build your own classifier: Human

    You can train a classifier yourself.

    Train

    ->Bolete
    ->Morel

    Test

    Build your own classifier: Machine Learning Program

    You can train a classifier yourself.

    Train

    In[]:=
    mushroomClassifier=Classify
    ->"Bolete",
    ->"Morel",
    ->"Bolete",
    ->"Morel",
    ->"Morel",
    ->"Bolete",
    ->"Morel",
    ->"Morel",
    ->"Bolete",
    ->"Bolete",
    ->"Morel",
    ->"Morel",
    ->"Bolete",
    ->"Bolete",
    ->"Morel",
    ->"Bolete"
    Out[]=
    ClassifierFunction
    Input type: Image
    Classes: Bolete,Morel
    Method: LogisticRegression
    Number of training examples: 16
    Data not saved. Save now

    Test

    More Classifiers

    Day or Night Classifier

    Feed a list of images, each with a label “Day” or “Night”, to Classify:
    The result is a classifier function that can accept new examples as input data and return a class or label as output that the classifier believes fits the input best:

    Try your own Classifier

    Try using Classify[ ] for identifying images of any of the following famous pairs:
  • Dogs and cats
  • Tom and Jerry
  • Chalk and cheese
  • Hammer and nails
  • Fish and chips
  • Ant and Dec
  • Batman and Robin
  • Asterix and Obelix
  • Handwritten Digit Classifier

    Here's a simple example of classifying handwritten digits as 0 or 1. You give the classifier a collection of training examples, followed by a particular handwritten digit. Then it'll tell you whether the digit you give is a 0 or 1.
    With training examples, Classify correctly identifies a handwritten 0:

    Can a classifier handle lots of examples?

    We looked at only a few examples:
    How about looking at many more examples?
    Note: Constructed from hand written digits extracted from handwriting samples
    There’s no way a human could process that data in seconds - right?
    Try the classifier on these samples:

    How do the Classifiers Work? (Hint: Remember Vector Spaces)

    In one dimension

    Say the goal is to predict if a vehicle is a car or a truck based on its weight in tons:

    In two dimensions

    In three dimensions

    Colors in 3D feature space (Red, Green, Blue):
    Based on how close they are to each other we can cluster them into three groups: the Red group, the Green group and the Blue group:

    Any data sample can be represented as a vector of numbers

    Calculate nearness based on numbers

    Find what number in a list is nearest to what you supply.
    Find what number in the list is nearest to 22:
    Find the nearest three numbers:

    Convert any data to numbers

    In Wolfram Language the Nearest function can work with a variety of data, including numerical, geospatial, textual, and visual, as well as dates and times.
    Find the 3 colors in the list that are nearest to the color you give:
    Find the 5 words nearest to “electric” in the list of words:
    There’s a notion of nearness for images too.
    Find the nearest image from a dataset of dog images:
    Train a nearest function:
    Find the image from the dataset that is nearest to these new sample images:

    Nearness as step to identifying

    Human’s Approach

    When we compare things—whether they’re colors or pictures of animals—we can think of identifying certain features that allow us to distinguish them.
  • For colors, a feature might be how light the color is, or how much red it contains.
  • For pictures of animals, a feature might be how furry the animal looks, or how pointy its ears are.
  • Machine’s Approach

    The machine learning function is able to identify an image because it has previously seen similar images and decides that this image is closest to the examples of “cheetah” images it has seen before:
    What if we try to provide the same image to the machine learning function but blur it a bit every time, i.e. we “muddy the input”?
    Progressively blur a picture of a cheetah:
    When the picture gets too blurred, ImageIdentify no longer thinks it' s a cheetah. What do you think this is an image of?
    What does the computer think of the images?
    Take one of the blurred images and look at all possible answers ImageIdentify came up with.
    ImageIdentify thinks this might be a cheetah, but it’s also likely to be a liger, or it could be a lion or a wildcat.
    When the image is sufficiently blurred, ImageIdentify can have wild ideas about what it might be.

    So what is machine learning?

  • How computers recognize patterns without being explicitly programmed...
  • A different way to program a computer.
    Instead of writing rules and providing explicit instructions, you are programming with help of data
    (showing lots and lots of examples;
    learning by trial and error, lots of practice and data).
  • Wolfram Cloud

    You are using a browser not supported by the Wolfram Cloud

    Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


    I understand and wish to continue anyway »

    You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.