仓库源文站点原文


layout: post title: "ML4T笔记 | 01-08 Optimizers: Building a parameterized model" date: "2018-01-15 01:15:15" categories: 计算机科学 auth: conge

tags: Machine_Learning Trading ML4T OMSCS

01 - What is an optimizer

image.png

What is an optimizer?: An optimizer is an algorithm that can:

How do we use an optimizer? three key steps.

  1. define a function that you want to minimize. define in Python and then the minimizer will call this function many, many times as it tries to find the minimum values for x that causes this function overall to be smallest.
  2. Choose an initial guess for x (might be close to the solution to the problem or choose a random value, or just some standard value).
  3. call the optimizer starts with that guess and it repeatedly calls a function, tests different values, and narrows in on the solution.

Time: 00:02:30

02 - Minimization example

Time: 00:02:10

03 - Minimizer in Python

Python code

Let's try a test run and see what happens.

Output

Time: 00:03:25

04 - Quiz: How to defeat a minimizer

Given the four function shapes to look at, which one(s) is harder to sovle and why?

Note: these are solvable by optimizers, but just hard. In fact, there are optimizers that can solve these problems with varying degrees of success. but sucess is not guareentted.

Time: 00:01:30

05 - Convex problems

image.png

Minimizer are especially good at solving convex problems.

The formal definition of a convex function.

A real valued function f(x) defined on an interval is called convex if the line segment between any two points on the graph of the function lies above the graph.

To tell if a function is vonvex:

  1. choose two points and draw a line between them.
  2. for each of these lines, if the line is above the graph, everywhere between those two points, then the function is convex between those points.

Time: 00:03:10

6 - Building a parameterized model

What should we use for that equation?

Time: 00:03:31

07 - quiz What is a good error metric

which of these formulae might be a good overall error measure?

My answer

Simply summing up the errors doesn't work, as some of them may be negative. Taking the absolute value or squared error solves that problem.

08 - Minimizer finds coefficients

Steps of a minimizer finding the coefficients of a line that best fits this data. (we need to give the minimizer an equation that it has to minimize).

  1. guess an initial C<sub>0</sub> and C<sub>1</sub> and that would be a line like this, and we would give that to the minimizer and let it go.
  2. the minimizer would measure the error with this particular line, it would fiddle with these values a little bit and see how much the error changed, try a new set of values see how that works.
  3. it's going to iterate, and eventually settle on what it thinks is the best solution.

Time: 00:01:16

09 - Fit a line to given data points

Define error function

Fit_line()

output

Time: 00:05:51

10 - And it works for polynomials too

We can fit even more complicated functions to data like this.

Our original polynomial is f(x) = 1.5x<sup>4</sup> - 10x <sup>3</sup> - 5 x<sup>2</sup>+ 60x + 50.

Let's look now at how we do that in code.

error function

Here's our function that finds the coefficients of the polynomial has just a few parameters.

And that's it that's how we use Python to create a model based on data.

Time: 00:03:07

13 - Wrapping up optimizers

Recap: We have learned

Where can you go from here?.

Time: 00:00:27

Total Time: 00:28:37

2018-01-15 初稿