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

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

正在回答

3 回答

調(diào)用sklearn包中datasets,里面有好像iris數(shù)據(jù)集

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

iris數(shù)據(jù)集,可以到我的百度網(wǎng)盤下載:

https://pan.baidu.com/s/17dK9fdGHzGY1SfI-s1pt6w

0 回復(fù) 有任何疑惑可以回復(fù)我~
class?AdalineG(object):????
????"""????
????eta:float????
????學(xué)習(xí)效率,處于0和1之間????????
????n_iter:int????對訓(xùn)練數(shù)據(jù)進(jìn)行學(xué)習(xí)改進(jìn)次數(shù)????????
????w_:一維向量????
????存儲權(quán)重?cái)?shù)值????????
????error_:????存儲每次迭代改進(jìn)時(shí),網(wǎng)絡(luò)對數(shù)據(jù)進(jìn)行錯誤判斷的次數(shù)????
????"""????????????
????def?__init__(self,eta=0.01,n_iter=50):????????
????????self.eta?=?eta????????
????????self.n_iter?=?n_iter????????????
????def?net_input(self,?X):????????
????????return?np.dot(X,?self.w_[1:])?+?self.w_[0]????????
????def?activation(self,?X):????????
????????return?self.net_input(X)???????
????def?predict(self,?X):????????
????????return?np.where(self.activation(X)?>=0,?1,?-1)????????
????def?fit(self,?X,?y):????????
????????"""????????
????????X:二維數(shù)組[n_sampls,?n_features]????????
????????n_samples?表示X中含有訓(xùn)練數(shù)據(jù)條目數(shù)????????
????????n_faetures?含有4個數(shù)據(jù)的一維向量,用于表示一條訓(xùn)練條目????????????????
????????y:一維向量????????
????????用于存儲每一訓(xùn)練條目對應(yīng)的正確分類????????
????????"""????????????????
????????self.w_?=?np.zeros(1?+?X.shape[1])????????
????????self.cost_?=?[]????????????????
????????for?i?in?range(self.n_iter):????????????
????????????output?=?self.net_input(X)????????????
????????????errors?=?(y-output)????????????
????????????self.w_[1:]?+=?self.eta?*?X.T.dot(errors)????????????
????????????self.w_[0]?+=?self.eta?*?errors.sum()????????????
????????????cost?=?(errors?**?2).sum()?/2.0????????????
????????????self.cost_.append(cost)????????
????????return?self
????????
????????
file?=?"D:/PyCharm_test_file/Jupyter_test/iris1.xlsx"?#此處添加iris數(shù)據(jù)集
import?pandas?as?pd
df?=?pd.read_excel(file,header=None)
import?matplotlib.pyplot?as?plt
import?numpy?as?np
y?=?df.loc[0:99,?4].values
y?=?np.where(y?==?'Iris-setosa',?-1,?1)
X?=?df.iloc[0:100,?[0,?2]].values


from?matplotlib.colors?import?ListedColormap
def?plot_decision_regions(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()????
????#將x1、x2最大最小值通過arange函數(shù)得到的向量,擴(kuò)展成兩個二維矩陣????
????xx1,?xx2?=?np.meshgrid(np.arange(x1_min,?x1_max,?resolution),?np.arange(x2_min,?x2_max,?resolution))????
????#預(yù)測????
????Z?=?classifier.predict(np.array([xx1.ravel(),?xx2.ravel()]).T)?#ravel還原成單維向量????
????#繪制????
????Z=?Z.reshape(xx1.shape)?#將Z轉(zhuǎn)換成與xx1一樣的二維數(shù)組????
????plt.contourf(xx1,?xx2,?Z,?alpha=0.4,?cmap=cmap)?#在兩組分類結(jié)果中間畫分割線-->必須線性可分????
????plt.xlim(xx1.min(),?xx1.max())????
????plt.ylim(xx2.min(),?xx2.max())????
????for?idx,?cl?in?enumerate(np.unique(y)):????????
????????plt.scatter(x=X[y==cl,?0],?y=X[y==cl,?1],?alpha=0.8,?c=cmap(idx),?marker=marker[idx],?label=cl)
????????
????????
????????
ada?=?AdalineG(eta=0.0001,?n_iter=50)
ada.fit(X,?y)
plot_decision_regions(X,?y,?classifier=ada)
plt.title('Adaline-Gradient?descent')
plt.rcParams['font.sans-serif']=['SimHei']
plt.xlabel('花莖長度')
plt.ylabel('花瓣長度')
plt.legend(loc='upper?left')
plt.show()
"""
打印出模型對數(shù)據(jù)判斷的錯誤次數(shù)(迭代過程)
"""
plt.plot(range(1,?len(ada.cost_)+1),?ada.cost_,?marker='o')
plt.xlabel('Epochs(迭代次數(shù))')
plt.ylabel('sum-squard-error')plt.show()


https://img1.sycdn.imooc.com//5b48654d0001d60203900554.jpg


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

舉報(bào)

0/150
提交
取消

代碼與數(shù)據(jù)

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

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

幫助反饋 APP下載

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

公眾號

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