Last active
August 16, 2016 13:36
-
-
Save darden1/e6e895c86f775c20143493dd77593af2 to your computer and use it in GitHub Desktop.
StudyMachineLearning_AdalineMatrixExpression.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- encoding: utf-8 -*- | |
import numpy as np | |
import pandas as pd | |
df = pd.read_csv("https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data", header=None) | |
y = df.iloc[0:4, 4].values | |
y = np.where(y == "Iris-setosa", -1, 1) | |
X = df.iloc[0:4, [0, 2]].values | |
#---特徴行列 | |
X=np.matrix(X) | |
m,n=X.shape | |
#---しきい値用に一番左側の列に1を追加 | |
X=np.c_[np.matrix(np.ones((m,1))),X] | |
#---教師データベクトル | |
y=np.matrix(y).T | |
#---重みベクトル | |
w=np.matrix(np.zeros((n+1,1))) | |
#---活性化関数 定数 | |
alpha=1 | |
#---特徴行列と重みベクトルの掛け合わせ | |
z=X*w | |
#---活性化関数出力ベクトル | |
phi=alpha*X*w | |
#---教師データと活性化関数出力の残差ベクトル | |
e=y-alpha*X*w | |
#---コスト関数 | |
J=e.T*e/2 | |
#---コスト関数の勾配 | |
gradJ=-alpha*X.T*y+alpha**2*X.T*X*w | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment