第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

缺少的那一節(jié)

我用的python3.7,調(diào)整了視頻中的錯(cuò)誤,函數(shù)的位置和命名問題,但是出現(xiàn)TypeError: can't multiply sequence by non-int of type 'float'這個(gè)錯(cuò)誤,python3中不能這么寫嗎,以下為我的感知器類代碼

import numpy as np
class Perception(object):
??? '''
??? eta:學(xué)習(xí)率
??? n_iter:權(quán)重向量的訓(xùn)練次數(shù)
??? w_:神經(jīng)分叉權(quán)重向量
??? error_:記錄神經(jīng)元判斷出錯(cuò)次數(shù)
??? '''
??? def __init__(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)
??????? n_samples:樣本量
??????? n_feature:神經(jīng)元分叉數(shù)量
??????? 例:x:[[1,2,3],[4,5,6]]
??????? n_samples:2
??????? n_feature:3
??????? y:[1,-1]
??????? '''
??????? '''
??????? 初始化權(quán)重向量為0
??????? 加一是因?yàn)閷⑶懊嫠惴ㄌ岬降膚0,也就是步調(diào)函數(shù)閾值
??????? w_:權(quán)重向量
??????? error_:錯(cuò)誤記錄向量
??????? '''
??????? self.errors_ = []
??????? self.w_ = np.zeros(1 + x.shape[1])
??????? for _ in range(self.n_iter):
??????????? errors = 0
??????????? for xi,target in zip(x,y):
??????????????? '''
??????????????? zip(x,y):[[1,2,3,1],[4,5,6,-1]]
??????????????? '''
??????????????? update = (self.eta) * (target - self.predict(xi))
??????????????? self.w_[1:] += update * xi
??????????????? self.w_[0] += update
??????????????? '''
??????????????? ▽w(n) = update * x[n]
??????????????? '''
??????????????? errors += int(update != 0.0)
??????????????? self.errors_.append(errors)
??????????????? pass
??????????? pass
??? def net_input(self,x):
??????? '''
??????? z = w0 * 1 + w1 * x1 +... +wn * xn
??????? '''
??????? z = np.dot(x,self.w_[1:]) + self.w_[0]
??????? return z
??????? pass
??? def predict(self,x):
??????? return np.where(self.net_input(x)>=0.0,1,-1)
??????? pass


正在回答

1 回答

我也用的python3.7,這是我的代碼,謝謝采納~

import?numpy?as?np

class?Perceptron(object):
????#?注釋1
????def?__init__(self,?eta?=?0.01,?n_iter?=?10):
????????self.eta?=?eta
????????self.n_iter?=?n_iter
????def?fit(self,?X,?y):
????????#?注釋2
????????self.w_?=?np.zeros(1?+?X.shape[1])
????????self.errors_?=?[]
????????for?_?in?range(self.n_iter):
????????????errors?=?0
????????????#?注釋3
????????????for?xi,?target?in?zip(X,?y):
????????????????update?=?self.eta?*?(target?-?self.predict(xi))
????????????????#?注釋4
????????????????self.w_[1:]?+=?update?*?xi
????????????????self.w_[0]?+=?update
????????????????errors?+=?int(update?!=?0.0)
????????????????self.errors_.append(errors)
????def?net_input(self,?X):
????????#?注釋5
????????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)
注釋1:
????eta:學(xué)習(xí)率
????n_iter:權(quán)重向量的訓(xùn)練次數(shù)
????w_:神經(jīng)分叉權(quán)重向量
????errors_:用于記錄神經(jīng)元判斷出錯(cuò)次數(shù)
注釋2:
????輸入訓(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,y:[1,?-1]

????初始化權(quán)重向量為0,加1是因?yàn)樘岬降膚0,即步調(diào)函數(shù)的閾值
注釋3:
????比如:X:[[1,?2,?3],?[4,?5,?6]
????所以y:[1,?-1],zip(X,?y):[[1,?2,?3,?1].?[4,?5,?6,?-1]]

????update?=?n?*?(y?-?y')
注釋4:
????xi是一個(gè)向量
????update?*?xi等價(jià)于:[?w1?=?x1*update,?w2?=?x2*update,?...]
注釋5:
????z?=?w0*1?+?w1*x1?+?w2*x2?+?...?
????np.dot()是做點(diǎn)積


3 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

缺少的那一節(jié)

我要回答 關(guān)注問題
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)