5
$\begingroup$

I am new to machine learning. I am confused about how a machine learning model remembers what it learns. And how it learns.

I know the basic workflow of machine learning: first is data gathering, then data preprocessing, then creating training and test data sets, then training the ML learning algorithm. After training, we test the accuracy of our model with test data. But I am confused about how the algorithm is trained and how it remembers what it learns.

$\endgroup$

closed as unclear what you're asking by Sean Owen Sep 3 '18 at 22:38

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

7
$\begingroup$

ML algorithms all learn a set of numbers associated with whatever model you're training. For a neural network, it's the weights on the network links. For regression, it's the coefficients. And so on. These numbers you can store and use later (most ML libraries have utilities for doing this). You use the coefficients to make predictions on data on which you have NOT trained the model.

The ML algorithm uses some sort of optimization for learning the coefficients. It might be gradient descent, or stochastic gradient descent, or xgboost, or any of a number of optimization algorithms. These are typically used to minimize a cost function. The definition of that cost function is model-dependent.

$\endgroup$
3
$\begingroup$

Welcome to Data Science SE! As a short answer has been given, I'll give a longer overview of the problem, starting with a analogous human approach. But first, a formal definition of machine learning from Mitchell:

"A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P if its performance at tasks in T, as measured by P, improves with experience E."

This essentially says: "Do something, get it wrong, *perform magic*, try again, repeat until happy"

It doesn't detail the magic part... and I guess that is what you are interested in. Well, one main inspiration for that magic within machine learning (and artificial intelligence) is humans - and how we learn. We generally follow the phrase "learning by doing". Let's use a stupid human example to begin with:

GOAL: you want to get a cookie from a jar

STEPS:

  1. you naïvely stretch out your arms, but you can't reach the jar... no cookie - you are unhappy
  2. you learn a trick e.g. getting a chair to stand on. Now you can reach the jar - you are happy
  3. you look in the jar and see 3 different cookies - you want chocolate chip but pick a raisin cookie... don't like the taste - unhappy
  4. you pick a different cookie... chocolate chip - happy

In this example above, steps 1 and 2 sound like reinforcement learning.... iteratively learning how to complete a task, exploring possibilities. Steps 3 and 4 are most like image classification... classifying and labelling images (types of cookies).

Comparing the main steps of learning - first the human brain view, then the machine learning equivalent as the second point:

  1. Initialisation

    • Your brain is the model, holding lots of information about your experience and how happy your are. It is combined to tell you what to do based on what you sense (input).
    • a model consisting of a combination of weights/coefficients define conditional behaviour. Inputs are combined and weighted with these to produce an output.
  2. Doing

    • You get feedback (cookie or not) - this tells you how to adjust your brain's model of the poblem at hand.
    • The machine learning model measures a numerical error based on its output and the expected result - putting a number on how bad was it's attempt was.
  3. Learning

    • the (average) human cannot now further explain how it improves. It tries something different... goes for a cookie with smaller dark coloured dots, the bigger cookie, etc. This is the magic part that gets into neuroscience.
    • an ML model can be explained. It uses an optimisation method to make sense of those errors... it changes the weights/coefficients in a way it thinks will reduce the error it measures.

We generally speak about gradient descent (more help) as a way to train the model - to help it learn. It is called gradient descent because we imagine the errors/cost of the model are like a hill that we want to descend i.e. we want to get to the bottom of it:

gradient descent curve. Going down the gradient

This curve shows how the iterative process of computing our error, updating the weights and repeating, takes us down the gradient of the error/cost. We do this iteratively, in little steps. The weights of the model are stored between stages - the weights are persistent between iterations. Once the model is happy, measuring small/acceptable errors, we are finished training and can use that hold-out test dataset to validate the model's performance.

Gradient descent (and e.g. backpropagation) are then really where learning happens. They're the methods by which we update the weights. They basically close the loop from (1) getting an error –how unhappy we are– to (2) being able to adjust those weights slightly in a way that would make us better at that task next time. This really equates to adding or subtracting a small amount from the existing weights. Exactly how much we add/subtract is controlled using the learning rate parameter. If it is big, we add/subtract big amounts - so learning fast. But that has its own problems - we cannot learn consistently and can get completely lost, so it is usually a small number ~ 0.001.

The weights we start with in a neural network are most commonly just random numbers. We ask the model to perform a task, then use gradient descent with the errors to slowly improve those random weights with tiny alterations. At the end, it is these weights that we save to disk on the computer. They are intellgient combinations of simply decimal numbers.


To get your head around machine learning and what it means, at the highest level, you might want to read an article like this.

I would suggest reading Michael Nielsen's eBook as a nice intuitive introduction - is a great place to start.

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.