一份 Python 機器學習線上指南

紅色石頭發表於2019-05-16

機器學習、深度學習如何更好、更有效率地學習?不外乎兩點:一是需要一份較完備的入門路線;二是教程與程式碼相結合提升學習效率。今天給大家推薦一份絕佳的機器學習入門完備資料,內容豐富、結合了教程與程式碼,而且通俗易懂,非常適合快速學習!

首先附上這份指南的 GitHub 地址:

https://github.com/machinelearningmindset/machine-learning-course

簡介

這份指南主要是提供一個全面而簡單的使用 Python 的機器學習課程。機器學習作為人工智慧的工具,是應用最廣泛的科學領域之一。大量關於機器學習的文獻已經發表。這個專案的目的是通過展示一系列使用 Python 的簡單而全面的教程來提供機器學習的最重要方面。在這個專案中,我們使用許多不同的眾所周知的機器學習框架(如 scikit-learn)構建了我們的教程。在這個專案中,你將學到:

  • 機器學習的定義是什麼?
  • 什麼時候開始的,什麼是趨勢演變?

  • 什麼是機器學習類別和子類別?

  • 什麼是最常用的機器學習演算法以及如何實現它們?

這份指南的目錄如下:

  • 機器學習基礎
    • 線性迴歸
    • 過擬合/欠擬合

    • 正則化

    • 交叉驗證

  • 監督式學習

    • 決策樹
    • kNN

    • 樸素貝葉斯

    • 邏輯迴歸

    • 支援向量機

  • 非監督式學習

    • 聚類
    • 主成分分析 PCA

  • 深度學習

    • 神經網路概述
    • 卷積神經網路

    • 自編碼器

    • 迴圈神經網路

下面我們來具體看一下這份指南!

1. 機器學習基礎

這部分主要包含了一些機器學習的基礎知識,包括線性迴歸、過擬合/欠擬合、正則化和交叉驗證。

每個知識點不僅包含了理論解釋,也有全面的程式碼講解。例如線性迴歸部分:

線性迴歸的示例程式碼:

import matplotlib.pyplot as plt
import seaborn as sns
from sklearn import datasets, linear_model
from sklearn.datasets import make_regression
from sklearn.model_selection import train_test_split

# Create a data set for analysis
x, y = make_regression(n_samples=500, n_features = 1, noise=25, random_state=0)

# Split the data set into testing and training data
x_train, x_test, y_train, y_test = train_test_split(x, y, random_state=0)

# Plot the data
sns.set_style("darkgrid")
sns.regplot(x_test, y_test, fit_reg=False)

# Remove ticks from the plot
plt.xticks([])
plt.yticks([])

plt.tight_layout()
plt.show()

2. 監督式學習

這部分主要包含了一些機器學習中的監督式學習,包括決策樹、kNN、樸素貝葉斯、邏輯迴歸、支援向量機。

例如支援向量機部分的詳細介紹:

支援向量機的示例程式碼:

# All the libraries we need for linear SVM
import numpy as np
import matplotlib.pyplot as plt
from sklearn import svm
# This is used for our dataset
from sklearn.datasets import load_breast_cancer


# =============================================================================
# We are using sklearn datasets to create the set of data points about breast cancer
# Data is the set data points
# target is the classification of those data points. 
# More information can be found athttps://scikit-learn.org/stable/modules/generated/sklearn.datasets.load_breast_cancer.html#sklearn.datasets.load_breast_cancer
# =============================================================================
dataCancer = load_breast_cancer()

# The data[:, x:n] gets two features for the data given. 
# The : part gets all the rows in the matrix. And 0:2 gets the first 2 columns 
# If you want to get a different two features you can replace 0:2 with 1:3, 2:4,... 28:30, 
# there are 30 features in the set so it can only go up to 30.
# If we wanted to plot a 3 dimensional plot then the difference between x and n needs to be 3 instead of two
data = dataCancer.data[:, 0:2]
target = dataCancer.target

# =============================================================================
# Creates the linear svm model and fits it to our data points
# The optional parameter will be default other than these two,
# You can find the other parameters at https://scikit-learn.org/stable/modules/generated/sklearn.svm.SVC.html
# =============================================================================
model = svm.SVC(kernel = 'linear', C = 10000)
model.fit(data, target)


# plots the points 
plt.scatter(data[:, 0], data[:, 1], c=target, s=30, cmap=plt.cm.prism)

# Creates the axis bounds for the grid
axis = plt.gca()
x_limit = axis.get_xlim()
y_limit = axis.get_ylim()

# Creates a grid to evaluate model
x = np.linspace(x_limit[0], x_limit[1], 50)
y = np.linspace(y_limit[0], y_limit[1], 50)
X, Y = np.meshgrid(x, y)
xy = np.c_[X.ravel(), Y.ravel()]

# Creates the decision line for the data points, use model.predict if you are classifying more than two 
decision_line = model.decision_function(xy).reshape(Y.shape)


# Plot the decision line and the margins
axis.contour(X, Y, decision_line, colors = 'k', levels=[0], 
linestyles=['-'])
# Shows the support vectors that determine the desision line
axis.scatter(model.support_vectors_[:, 0], model.support_vectors_[:, 1], s=100,
linewidth=1, facecolors='none', edgecolors='k')

# Shows the graph
plt.show()

3. 非監督式學習

這部分主要包含了一些機器學習中的非監督式學習,包括聚類、主成分分析 PCA。

指南同樣包含了各個演算法的理論介紹和 Python 程式碼實現兩大部分。

4. 深度學習

這部分主要介紹的是深度學習知識,包括神經網路概述、卷積神經網路、自編碼器、迴圈神經網路。

這部分對深度學習與神經網路作了詳細的介紹,例如神經網路的反向傳播:

更多精彩內容,等待你去發掘~

線上指南

這份機器學習完備教程除了在 GitHub 上釋出之外,作者也公佈了該教程的線上閱讀地址:

https://machine-learning-course.readthedocs.io/en/latest/index.html#

線上閱讀,體驗感爆棚有沒有?一份不錯的機器學習入門教程,趕快去嚐鮮吧~


相關文章