-
權(quán)重更新算法示例2
查看全部 -
權(quán)重更新算法示例2
查看全部 -
權(quán)重更新算法示例
查看全部 -
權(quán)重更新算法
查看全部 -
神經(jīng)網(wǎng)絡查看全部
-
使用anaconda,jupyter查看全部
-
喜歡這樣念念碎的老師,哈哈查看全部
-
2018/03/10查看全部
-
軟件、代碼查看全部
-
第3段 from matplotlib.colors import ListedColormap def plot_decision_regions(x,y,classifier,resolution=0.02): 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() xx1,xx2 = np.meshgrid(np.arange(x1_min,x1_max,resolution),np.arange(x2_min,x2_max,resolution)) Z = classifier.predict(np.array([xx1.ravel(),xx2.ravel()]).T) Z = Z.reshape(xx1.shape) plt.contourf(xx1,xx2,Z,alpha=0.4,cmap=cmap) plt.xlim(xx1.min(),xx1.max()) plt.ylim(xx2.min(),xx2.max()) plt.scatter(X[:50,0],X[:50,1],color='red',marker='o',label='setosa') plt.scatter(X[50:100,0],X[50:100,1],color='blue',marker='x',label='versicolor') plt.xlabel(u'花徑長度',fontproperties='SimHei') plt.ylabel(u'花瓣長度',fontproperties='SimHei') plt.legend(loc='upper left') plt.show() plot_decision_regions(X,y,ppn,resolution=0.02)查看全部
-
第2段 import pandas as pd file = 'http://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' df = pd.read_csv(file,header=None) #header=None 數(shù)據(jù)第一行是有用數(shù)據(jù),不是表頭 print(df.head(10)) # 顯示前十行 #數(shù)據(jù)可視化 scatter 散點圖 import matplotlib.pyplot as plt import numpy as np y = df.loc[0:100,4].values y = np.where(y == 'Iris-setosa',-1,1) X = df.iloc[0:100,[0,2]].values #plt.scatter(X[:50,0],X[:50,1],color='red',marker='o',label='setosa') #plt.scatter(X[50:100,0],X[50:100,1],color='blue',marker='x',label='versicolor') #plt.xlabel('花瓣長度') 亂碼坐標不顯示 #plt.xlabel(u'花瓣長度',fontproperties='SimHei') #plt.ylabel(u'花徑長度',fontproperties='SimHei') #plt.legend(loc='upper left') #plt.show() ppn = Perceptron(eta=0.1,n_iter=10) ppn.fit(X,y) plt.plot(range(1,len(ppn.errors_)+1),ppn.errors_,marker='o') plt.xlabel(u'Epochs',fontproperties='SimHei') plt.ylabel(u'錯誤分類次數(shù)',fontproperties='SimHei') plt.show()查看全部
-
基本按著老師的寫的,能出圖~ 筆記字數(shù)有限制,代碼分了幾部分,注釋參考老師的講解。 (第1段) # -*- coding: utf-8 -*- import numpy as np class Perceptron(object): def __init__(self, eta = 0.01, n_iter=10): self.eta = eta; self.n_iter = n_iter; pass 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) pass pass pass def net_input(self, X): 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 pass查看全部
-
權(quán)重更新查看全部
-
算法總結(jié)查看全部
-
機器學習查看全部
舉報
0/150
提交
取消