【統(tǒng)計學習方法】 第2章 感知機課后習題(三)
點擊上方“公眾號”可訂閱哦!
“這個公眾號在我的新作品中幫助我毫不費力地使用了解決萬有引力的問題。?我現(xiàn)在有更多時間站在樹下,被蘋果擊中?!?/p>
Isaac Newton
本篇文章是課后三個習題。
1
●
題目:
Minsky 與 Papert 指出:感知機因為是線性模型,所有不能表示復雜的函數(shù),如異或(XOR)。驗證感知機為什么不能表示異或。
解答:
首先,來看異或函數(shù)的運算,

import matplotlib.pyplot as pltimport numpy as npimport pandas as pd%matplotlib inlinex1 = [1, 1, -1, -1]x2 = [1, -1, 1, -1]y = [-1, 1, 1, -1]x1 = np.array(x1)x2 = np.array(x2)y = np.array(y)# np.c_是按行連接兩個矩陣,就是把兩矩陣左右相加,要求行數(shù)相等。data = np.c_[x1, x2, y]data = pd.DataFrame(data, index=None, columns=['x1', 'x2', 'y'])data.head()positive = data.loc[data['y'] == 1]negative = data.loc[data['y'] == -1]plt.xlim(-2, 2)plt.ylim(-2, 2)plt.xticks([-2, -1, 0, 1, 2])plt.yticks([-2, -1, 0, 1, 2])plt.xlabel("x1")plt.ylabel("x2")plt.plot(positive['x1'], positive['x2'], "ro")plt.plot(negative['x1'], negative['x2'], "gx")plt.show()

顯然,線性不可分。
2
●
題目:
模仿例題2.1,構(gòu)建從訓練數(shù)據(jù)集求解感知機模型的例子。
解答:
from sklearn.linear_model import Perceptronimport numpy as npX_train = np.array([[3, 3], [4, 3], [1, 1]])y = np.array([1, 1, -1])perceptron_model = Perceptron()perceptron_model.fit(X_train, y)print("w:", perceptron_model.coef_, "\nb:", perceptron_model.intercept_, "\n")result = perceptron_model.predict(X_train)print(result)
w: [[1. 0.]]b: [-2.][ 1 1 -1]
3
●
題目:
證明以下定理:樣本集線性可分的充分必要條件是正實例點集所構(gòu)成的凸殼與負實例點集所構(gòu)成的凸殼互不相交。
解答:
????略
?END

深度學習入門筆記
微信號:sdxx_rmbj
日常更新學習筆記、論文簡述
評論
圖片
表情

