机器学习入门 - Google的机器学习速成课程

1 - MLCC

经过机器学习,能够有效地解读数据的潜在含义,甚至能够改变思考问题的方式,使用统计信息而非逻辑推理来处理问题。 Google的机器学习速成课程(MLCC,machine-learning crash-course):https://developers.google.com/machine-learning/crash-course/ 支持多语言,共25节课程,包含40多项练习,有对算法实际运用的互动直观展现,能够更容易地学习和实践机器学习概念。 官方预估时间大约15小时(实际花费时间根据我的状况而定,差别较大)。php

注意:这里的时间长度指的是教程播放和阅读的时间,而不是你“真正”理解吸取和练习的时间。 实际上,对于“小白”阶段的新手,可能要投入数倍于此的精力,才能完成整个学习过程(观看、阅读、理解、练习、了解相关知识点、等等)。html

本课程将解答以下问题:python

  • 机器学习与传统编程有何不一样?
  • 什么是损失,如何衡量损失?
  • 梯度降低法的运做方式是怎样的?
  • 如何肯定个人模型是否有效?
  • 怎样为机器学习提供个人数据?
  • 如何构建深度神经网络?

机器学习术语表git

1.1 - 练习环境:本地运行

MLCC相关练习:https://developers.google.com/machine-learning/crash-course/exercisesgithub

涉及的命令web

(base) >conda create -n mlcc pip python=3.6
(base) >conda activate mlcc
(mlcc) >pip --proxy="10.144.1.10:8080" install --ignore-installed --upgrade tensorflow matplotlib pandas sklearn scipy seaborn  # pip使用代理
(mlcc) >pip install --ignore-installed --upgrade tensorflow matplotlib pandas sklearn scipy seaborn -i https://mirrors.ustc.edu.cn/pypi/web/simple/  # pip使用国内源

示例算法

(base) C:\Users\guowli>conda create -n mlcc pip python=3.6
Collecting package metadata: done
Solving environment: done

## Package Plan ##

  environment location: C:\Office-Tools\Anaconda3\envs\mlcc

  added / updated specs:
    - pip
    - python=3.6


The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    certifi-2019.3.9           |           py36_0         156 KB  defaults
    pip-19.1.1                 |           py36_0         1.9 MB  defaults
    python-3.6.8               |       h9f7ef89_7        20.3 MB  defaults
    setuptools-41.0.1          |           py36_0         663 KB  defaults
    sqlite-3.28.0              |       he774522_0         945 KB  defaults
    vs2015_runtime-14.15.26706 |       h3a45250_4         2.4 MB  defaults
    wheel-0.33.2               |           py36_0          57 KB  defaults
    wincertstore-0.2           |   py36h7fe50ca_0          13 KB  defaults
    ------------------------------------------------------------
                                           Total:        26.4 MB

The following NEW packages will be INSTALLED:

  certifi            pkgs/main/win-64::certifi-2019.3.9-py36_0
  pip                pkgs/main/win-64::pip-19.1.1-py36_0
  python             pkgs/main/win-64::python-3.6.8-h9f7ef89_7
  setuptools         pkgs/main/win-64::setuptools-41.0.1-py36_0
  sqlite             pkgs/main/win-64::sqlite-3.28.0-he774522_0
  vc                 pkgs/main/win-64::vc-14.1-h0510ff6_4
  vs2015_runtime     pkgs/main/win-64::vs2015_runtime-14.15.26706-h3a45250_4
  wheel              pkgs/main/win-64::wheel-0.33.2-py36_0
  wincertstore       pkgs/main/win-64::wincertstore-0.2-py36h7fe50ca_0


Proceed ([y]/n)? y


Downloading and Extracting Packages
setuptools-41.0.1    | 663 KB    | ######################################################################### | 100%
certifi-2019.3.9     | 156 KB    | ######################################################################### | 100%
wincertstore-0.2     | 13 KB     | ######################################################################### | 100%
pip-19.1.1           | 1.9 MB    | ######################################################################### | 100%
vs2015_runtime-14.15 | 2.4 MB    | ######################################################################### | 100%
wheel-0.33.2         | 57 KB     | ######################################################################### | 100%
python-3.6.8         | 20.3 MB   | ######################################################################### | 100%
sqlite-3.28.0        | 945 KB    | ######################################################################### | 100%
Preparing transaction: done
Verifying transaction: done
Executing transaction: done
#
# To activate this environment, use
#
#     $ conda activate mlcc
#
# To deactivate an active environment, use
#
#     $ conda deactivate


(base) C:\Users\guowli>conda env list
# conda environments:
#
base                  *  C:\Office-Tools\Anaconda3
mlcc                     C:\Office-Tools\Anaconda3\envs\mlcc


(base) C:\Users\guowli>conda activate mlcc

(mlcc) C:\Users\guowli>pip list
Package      Version
------------ --------
certifi      2019.3.9
pip          19.1.1
setuptools   41.0.1
wheel        0.33.2
wincertstore 0.2

(mlcc) C:\Users\guowli>pip --proxy="10.144.1.10:8080" install --ignore-installed --upgrade tensorflow matplotlib pandas sklearn scipy seaborn
Collecting tensorflow
  Downloading https://files.pythonhosted.org/packages/bf/58/34bfa8fa17f86333361172b3b502e805195180f19a7496ad0f6149138d55/tensorflow-1.13.1-cp36-cp36m-win_amd64.whl (63.1MB)
     |████████████████████████████████| 63.1MB 598kB/s
Collecting matplotlib
  Downloading https://files.pythonhosted.org/packages/21/4c/35fa1837a705f33621604a1967b1505bd3f695940fdf02fad77ef11de196/matplotlib-3.0.3-cp36-cp36m-win_amd64.whl (9.1MB)
     |████████████████████████████████| 9.1MB 544kB/s
......
......
......
Collecting joblib>=0.11 (from scikit-learn->sklearn)
  Downloading https://files.pythonhosted.org/packages/cd/c1/50a758e8247561e58cb87305b1e90b171b8c767b15b12a1734001f41d356/joblib-0.13.2-py2.py3-none-any.whl (278kB)
     |████████████████████████████████| 286kB 6.4MB/s
Building wheels for collected packages: sklearn, absl-py, gast, termcolor
  Building wheel for sklearn (setup.py) ... done
  Stored in directory: C:\Users\guowli\AppData\Local\pip\Cache\wheels\76\03\bb\589d421d27431bcd2c6da284d5f2286c8e3b2ea3cf1594c074
  Building wheel for absl-py (setup.py) ... done
  Stored in directory: C:\Users\guowli\AppData\Local\pip\Cache\wheels\ee\98\38\46cbcc5a93cfea5492d19c38562691ddb23b940176c14f7b48
  Building wheel for gast (setup.py) ... done
  Stored in directory: C:\Users\guowli\AppData\Local\pip\Cache\wheels\5c\2e\7e\a1d4d4fcebe6c381f378ce7743a3ced3699feb89bcfbdadadd
  Building wheel for termcolor (setup.py) ... done
  Stored in directory: C:\Users\guowli\AppData\Local\pip\Cache\wheels\7c\06\54\bc84598ba1daf8f970247f550b175aaaee85f68b4b0c5ab2c6
Successfully built sklearn absl-py gast termcolor
Installing collected packages: six, setuptools, protobuf, numpy, absl-py, markdown, werkzeug, wheel, grpcio, tensorboard, astor, keras-preprocessing, gast, mock, tensorflow-estimator, termcolor, h5py, keras-applications, tensorflow, kiwisolver, pyparsing, python-dateutil, cycler, matplotlib, pytz, pandas, scipy, joblib, scikit-learn, sklearn, seaborn
Successfully installed absl-py-0.7.1 astor-0.7.1 cycler-0.10.0 gast-0.2.2 grpcio-1.20.1 h5py-2.9.0 joblib-0.13.2 keras-applications-1.0.7 keras-preprocessing-1.0.9 kiwisolver-1.1.0 markdown-3.1 matplotlib-3.0.3 mock-3.0.5 numpy-1.16.3 pandas-0.24.2 protobuf-3.7.1 pyparsing-2.4.0 python-dateutil-2.8.0 pytz-2019.1 scikit-learn-0.21.0 scipy-1.2.1 seaborn-0.9.0 setuptools-41.0.1 six-1.12.0 sklearn-0.0 tensorboard-1.13.1 tensorflow-1.13.1 tensorflow-estimator-1.13.0 termcolor-1.1.0 werkzeug-0.15.2 wheel-0.33.4

(mlcc) C:\Users\guowli>
(mlcc) C:\Users\guowli>pip list
Package              Version
-------------------- --------
absl-py              0.7.1
astor                0.7.1
certifi              2019.3.9
cycler               0.10.0
gast                 0.2.2
grpcio               1.20.1
h5py                 2.9.0
joblib               0.13.2
Keras-Applications   1.0.7
Keras-Preprocessing  1.0.9
kiwisolver           1.1.0
Markdown             3.1
matplotlib           3.0.3
mock                 3.0.5
numpy                1.16.3
pandas               0.24.2
pip                  19.1.1
protobuf             3.7.1
pyparsing            2.4.0
python-dateutil      2.8.0
pytz                 2019.1
scikit-learn         0.21.0
scipy                1.2.1
seaborn              0.9.0
setuptools           41.0.1
six                  1.12.0
sklearn              0.0
tensorboard          1.13.1
tensorflow           1.13.1
tensorflow-estimator 1.13.0
termcolor            1.1.0
Werkzeug             0.15.2
wheel                0.33.4
wincertstore         0.2

(mlcc) C:\Users\guowli>

1.2 - 练习环境:在线运行

1.3 - 前提条件和准备工做

MLCC Prereqs and prework:https://developers.google.com/machine-learning/crash-course/prereqs-and-preworksql

前提条件

掌握入门级代数知识。 
    了解变量和系数、线性方程式、函数图和直方图(熟悉对数和导数等更高级的数学概念会有帮助,但不是必需条件)。

熟练掌握编程基础知识,而且具备一些使用 Python 进行编码的经验。
    机器学习速成课程中的编程练习是经过TensorFlow并使用Python进行编码的。
    无需拥有任何 TensorFlow经验,但应该可以熟练阅读和编写包含基础编程结构(例如,函数定义/调用、列表和字典、循环和条件表达式)的Python代码。

准备工做

Pandas 使用入门
    机器学习速成课程中的编程练习使用 Pandas 库来操控数据集。
    若是不熟悉 Pandas,建议先学习Pandas 简介教程,该教程介绍了练习中使用的主要 Pandas 功能。

低阶 TensorFlow 基础知识
   机器学习速成课程中的编程练习使用 TensorFlow 的高阶 tf.estimator API 来配置模型。
   若是有兴趣从头开始构建 TensorFlow 模型,请学习如下教程:
     - TensorFlow Hello World:在低阶 TensorFlow 中编码的“Hello World”。
     - TensorFlow 编程概念:演示了 TensorFlow 应用中的基本组件:张量、指令、图和会话。
     - 建立和操控张量:张量快速入门 - TensorFlow 编程中的核心概念。此外,还回顾了线性代数中的矩阵加法和乘法概念。

1.4 - 主要概念和工具

数学

代数
    - 变量、系数和函数
    - 线性方程式
    - 对数和对数方程式
    - S型函数

线性代数
    - 张量和张量等级
    - 矩阵乘法

三角学
    - Tanh(做为激活函数进行讲解,无需提早掌握相关知识)

统计信息
    - 均值、中间值、离群值和标准误差
    - 可以读懂直方图

微积分(可选,适合高级主题)
    - 导数概念(您没必要真正计算导数)
    - 梯度或斜率
    - 偏导数(与梯度紧密相关)
    - 链式法则(带您全面了解用于训练神经网络的反向传播算法)

Python(https://docs.python.org/3/tutorial/)

基础 Python
    - 定义和调用函数:使用位置和关键字参数
    - 字典、列表、集合(建立、访问和迭代)
    - for 循环:包含多个迭代器变量的 for 循环(例如 for a, b in [(1,2), (3,4)])
    - if/else 条件块和条件表达式
    - 字符串格式(例如 '%.2f' % 3.14)
    - 变量、赋值、基本数据类型(int、float、bool、str)
    - pass 语句
中级 Python
    - 列表推导式
    - Lambda 函数

第三方Python库(无需提早熟悉,在须要时查询相关内容)

Matplotlib(适合数据可视化)
    - pyplot 模块
    - cm 模块
    - gridspec 模块

Seaborn(适合热图)
    - heatmap 函数

Pandas(适合数据处理)
    - DataFrame 类

NumPy(适合低阶数学运算)
    - linspace 函数
    - random 函数
    - array 函数
    - arange 函数

Scikit-Learn(适合评估指标)
   - metrics 模块

Bash

2 - 下一步

2.1 - Google的机器学习指南

https://developers.google.com/machine-learning/guides/ 经过简单的逐步演示介绍如何利用最佳作法解决常见的机器学习问题。shell

2.2 - Machine Learning Practica

Google的机器学习实践:https://developers.google.com/machine-learning/practica/编程

2.3 - 深刻了解官网文档

以TensorFlow为例: