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

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

dimension is 100 but corresponding boolean dimension is 101

IndexError? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? Traceback (most recent call last)?

<ipython-input-45-a65b21b8df17> in <module>

?----> 1 plot_decision_regions(X,y,ppn,resolution=0.02)? ? ? ?

2 plt.xlabel('花徑長(zhǎng)度')? ? ? ?

3 plt.ylabel('花瓣長(zhǎng)度') ? ? ?

4 plt.legend(loc='upper left') ? ? ?

5 plt.show()

<ipython-input-44-85f310d48d44> in plot_decision_regions(X, y, classifier, resolution) ? ??

30 ?? ??

31 ? ? for idx,cl in enumerate(np.unique(y)):

---> 32 ? ? ? ? plt.scatter(x=X[y==cl,0],y=X[y==cl,1],alpha=0.8,c=cmap(idx),marker=marker[idx],label=cl)

IndexError: boolean index did not match indexed array along dimension 0; dimension is 100 but corresponding boolean dimension is 101

正在回答

2 回答

望采納~~

import?numpy?as?np
import?pandas?as?pd?
import?matplotlib.pyplot?as?plt
import?numpy?as?np
from?matplotlib.colors?import?ListedColormap

class?Perceptron(object):
????def?__init__(self,?eta?=?0.01,?n_iter?=?10):
????????self.eta?=?eta
????????self.n_iter?=?n_iter
????def?fit(self,?X,?y):
????????self.w_?=?np.zeros(1?+?X.shape[1])
????????self.errors_?=?[]
????????for?_?in?range(self.n_iter):
????????????errors?=?0
????????????for?xi,?target?in?zip(X,?y):
????????????????update?=?self.eta?*?(target?-?self.predict(xi))
????????????????self.w_[1:]?+=?update?*?xi
????????????????self.w_[0]?+=?update
????????????????errors?+=?int(update?!=?0.0)
????????????????self.errors_.append(errors)
????def?net_input(self,?X):
????????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)
????????
file?=?"C:/Users/YYDL/Desktop/data.csv"
df?=?pd.read_csv(file,?header?=?None)
y?=?df.loc[0:100,?4].values
y?=?np.where(y?==?'Iris-setosa',?-1,?1)
X?=?df.iloc[0:100,?[0,?2]].values
ppn?=?Perceptron(eta=0.1,?n_iter=10)
ppn.fit(X,?y)

def?plot_decision_region(X,?y,?classifier,?resolution=0.02):
????marker?=?('s',?'x',?'o',?'v')
????colors?=?('red',?'blue',?'lightgreen',?'gray',?'cyan')
????cmap?=?ListedColormap(colors[:len(np.unique(y))])
????x1_min,?x1_max?=?X[:,?0].min()?-?1,?X[:,?0].max()
????x2_min,?x2_max?=?X[:,?1].min()?-?1,?X[:,?1].max()
????print(x1_min,?x1_max)
????print(x2_min,?x2_max)
????xx1,?xx2?=?np.meshgrid(np.arange(x1_min,?x1_max,?resolution),?np.arange(x2_min,?x2_max,?resolution))
????print(np.arange(x1_min,?x1_max,?resolution).shape)
????print(np.arange(x1_min,?x1_max,?resolution))
????print(xx1.shape)
????print(xx1)
????print(np.arange(x2_min,?x2_max,?resolution).shape)
????print(np.arange(x2_min,?x2_max,?resolution))
????print(xx2.shape)
????print(xx2)
plot_decision_region(X,?y,?ppn,?resolution=0.02)


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

y = df.loc[0:100, 4].values改為y = df.iloc[0:100, 4].values

看出區(qū)別了嗎?loc前面多個(gè)i。不然y的維度為101。

當(dāng)然你也可以直接改成y = df.loc[0:99, 4].values

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

舉報(bào)

0/150
提交
取消

dimension is 100 but corresponding boolean dimension is 101

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

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

幫助反饋 APP下載

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

公眾號(hào)

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