課程
/后端開發(fā)
/Python
/機(jī)器學(xué)習(xí)-實(shí)現(xiàn)簡(jiǎn)單神經(jīng)網(wǎng)絡(luò)
代碼沒(méi)有地方下載嗎
2017-07-12
源自:機(jī)器學(xué)習(xí)-實(shí)現(xiàn)簡(jiǎn)單神經(jīng)網(wǎng)絡(luò) 3-2
正在回答
```
import numpy as np
class perceptron(object):
? ? """
? ? eta :學(xué)習(xí)率
? ? n_iter: 權(quán)重向量的訓(xùn)練次數(shù)
? ? w_: 神經(jīng)分叉權(quán)重向量
? ? errors_: 用于記錄神經(jīng)元判斷出錯(cuò)次數(shù)
? ? def _int_(self,eta=0.01,n_iter=10):
? ? ? ? self.eta=eta;
? ? ? ? self.n_iter=n_iter;
? ? ? ? pass
? ? def fit(self,x,y):
? ? ? ? """
? ? ? ? 輸入訓(xùn)練數(shù)據(jù),培訓(xùn)神經(jīng)元,x輸入樣本向量,y對(duì)應(yīng)樣本分類
? ? ? ? x:shape[n_samples,n_features]
? ? ? ? x:[[1,2,3],[4,5,6]]
? ? ? ? n_samples: 2 (輸入樣本量)
? ? ? ? n_features:3 (輸入的信號(hào)有多少個(gè))
? ? ? ??
? ? ? ? y:[1,-1]
? ? ? ? 初始化權(quán)重向量為0
? ? ? ? self.w_=np.zero(1+x.shape[1]);
? ? ? ? self.errors_=[]
? ? ? ? 訓(xùn)練次數(shù)循環(huán)
? ? ? ? for _ in range(self.n_iter):
? ? ? ? ? ? errors =0
? ? ? ? ? ? """
? ? ? ? ? ? x:[[1,2,3],[4,5,6]]
? ? ? ? ? ? y:[1,-1]
? ? ? ? ? ? zip(x,y)=[[1,2,3,1],[4,5,6,-1]]
? ? ? ? ? ? for xi,target in zip(x,y):
? ? ? ? ? ? ? ? """
? ? ? ? ? ? ? ? update=η*(y-y')
? ? ? ? ? ? ? ? update =self.eta*(target-self.predict(xi))
? ? ? ? ? ? ? ? xi 是一個(gè)向量
? ? ? ? ? ? ? ? self.w_[1:]+=update*xi等價(jià):
? ? ? ? ? ? ? ? [▽w(1)=x[1]*update,▽w(2)=x[2]*update,▽w(3)=x[3]*update,]
? ? ? ? ? ? ? ? self.w_[1:]+=update*xi
? ? ? ? ? ? ? ? self.w_[0]+=update;
? ? ? ? ? ? ? ? errors+=int(update !=0.0)
? ? ? ? ? ? ? ? self.errors_.appand(errors)
? ? ? ? ? ? ? ? pass
? ? ? ? ? ??
? ? ? ? ? ? pass
? ? ? ? def net_input(self,x):
? ? ? ? ? ? z= W0*1+ W1*X1+ ....Wn*Xn
? ? ? ? ? ? return np.dot(x,self.w_[1:])+self.w_[0]
? ? ? ? def predict(self,x):
? ? ? ? ? ? return np.where(self,net_input(x)>=0.0,1,-1)
沒(méi)有下載!
舉報(bào)
人工智能時(shí)代,你準(zhǔn)備好成為抓住機(jī)遇的那百分之二嗎。
1 回答現(xiàn)在的視頻不能下載到本地離線學(xué)習(xí)了嗎?
3 回答有木有完整的代碼
1 回答代碼調(diào)試有屬性錯(cuò)誤啊
2 回答運(yùn)行視頻中的代碼有問(wèn)題
1 回答代碼運(yùn)行有誤,大神們幫忙看看
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-10-14
```
import numpy as np
class perceptron(object):
? ? """
? ? eta :學(xué)習(xí)率
? ? n_iter: 權(quán)重向量的訓(xùn)練次數(shù)
? ? w_: 神經(jīng)分叉權(quán)重向量
? ? errors_: 用于記錄神經(jīng)元判斷出錯(cuò)次數(shù)
? ? """
? ? def _int_(self,eta=0.01,n_iter=10):
? ? ? ? self.eta=eta;
? ? ? ? self.n_iter=n_iter;
? ? ? ? pass
? ? def fit(self,x,y):
? ? ? ? """
? ? ? ? 輸入訓(xùn)練數(shù)據(jù),培訓(xùn)神經(jīng)元,x輸入樣本向量,y對(duì)應(yīng)樣本分類
? ? ? ? x:shape[n_samples,n_features]
? ? ? ? x:[[1,2,3],[4,5,6]]
? ? ? ? n_samples: 2 (輸入樣本量)
? ? ? ? n_features:3 (輸入的信號(hào)有多少個(gè))
? ? ? ??
? ? ? ? y:[1,-1]
? ? ? ? """
? ? ? ? """
? ? ? ? 初始化權(quán)重向量為0
? ? ? ??
? ? ? ? """
? ? ? ? self.w_=np.zero(1+x.shape[1]);
? ? ? ? self.errors_=[]
? ? ? ??
? ? ? ? """
? ? ? ? 訓(xùn)練次數(shù)循環(huán)
? ? ? ? """
? ? ? ? for _ in range(self.n_iter):
? ? ? ? ? ? errors =0
? ? ? ? ? ? """
? ? ? ? ? ? x:[[1,2,3],[4,5,6]]
? ? ? ? ? ? y:[1,-1]
? ? ? ? ? ? zip(x,y)=[[1,2,3,1],[4,5,6,-1]]
? ? ? ? ? ? """
? ? ? ? ? ? for xi,target in zip(x,y):
? ? ? ? ? ? ? ? """
? ? ? ? ? ? ? ? update=η*(y-y')
? ? ? ? ? ? ? ? """
? ? ? ? ? ? ? ? update =self.eta*(target-self.predict(xi))
? ? ? ? ? ? ? ? """
? ? ? ? ? ? ? ? xi 是一個(gè)向量
? ? ? ? ? ? ? ? self.w_[1:]+=update*xi等價(jià):
? ? ? ? ? ? ? ? [▽w(1)=x[1]*update,▽w(2)=x[2]*update,▽w(3)=x[3]*update,]
? ? ? ? ? ? ? ? """
? ? ? ? ? ? ? ? self.w_[1:]+=update*xi
? ? ? ? ? ? ? ? self.w_[0]+=update;
? ? ? ? ? ? ? ? errors+=int(update !=0.0)
? ? ? ? ? ? ? ? self.errors_.appand(errors)
? ? ? ? ? ? ? ? pass
? ? ? ? ? ??
? ? ? ? ? ? pass
? ? ? ? def net_input(self,x):
? ? ? ? ? ? """
? ? ? ? ? ? z= W0*1+ W1*X1+ ....Wn*Xn
? ? ? ? ? ? """
? ? ? ? ? ? return np.dot(x,self.w_[1:])+self.w_[0]
? ? ? ? ? ? pass
? ? ? ? def predict(self,x):
? ? ? ? ? ? return np.where(self,net_input(x)>=0.0,1,-1)
? ? ? ? pass
```
2017-08-23
沒(méi)有下載!