亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

python--MLP神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)手寫數(shù)字識別

系統(tǒng) 2479 0
  • 概述

神經(jīng)網(wǎng)路顧名思義將生物的神經(jīng)系統(tǒng)中的興奮與抑制比作計(jì)算機(jī)中的0和1

知識點(diǎn):

  1. 神經(jīng)網(wǎng)絡(luò)原理
  2. 神經(jīng)網(wǎng)絡(luò)中的非線性矯正
  3. 神經(jīng)網(wǎng)絡(luò)參數(shù)設(shè)置
  • 參數(shù)設(shè)置

重要參數(shù):

activation:隱藏單元進(jìn)行非線性化的方法,一共4總:identity,logistic,tanh,relu

alpha:正則化參數(shù),默認(rèn)為0.0001,參數(shù)越大算法越簡單

hidden_layer_size:設(shè)置隱藏層的結(jié)點(diǎn)和層數(shù):[10,10]表示2層,每層結(jié)點(diǎn)為10? ? ? ?

?

  • 圖像分析

            
              import numpy as np
from sklearn.neural_network import MLPClassifier
from sklearn.datasets import load_wine

from sklearn.model_selection import train_test_split
wine = load_wine()
X = wine.data[:,:2]#只取前2個(gè)屬性
y = wine.target
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=0)

mlp = MLPClassifier(solver = 'lbfgs',hidden_layer_sizes=[100,100],activation='tanh',alpha=1)
mlp.fit(X_train,y_train)

import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap

cmap_light = ListedColormap(['#FFAAAA','#AAFFAA','#AAAAFF'])
cmap_bold = ListedColormap(['#FF0000','#00FF00','#0000FF'])
                            
x_min, x_max = X[:,0].min() -1,X[:,0].max()+1
y_min, y_max = X[:,1].min() -1,X[:,1].max()+1
xx,yy = np.meshgrid(np.arange(x_min,x_max,.02),np.arange(y_min,y_max,.02))
z = mlp.predict(np.c_[xx.ravel(),yy.ravel()])
z = z.reshape(xx.shape)

plt.figure()
plt.pcolormesh(xx,yy,z,cmap=cmap_light)

plt.scatter(X[:,0],X[:,1],c=y,cmap=cmap_bold,edgecolor='k',s=20)
plt.xlim(xx.min(),xx.max())
plt.ylim(yy.min(),yy.max())

plt.show()

print("訓(xùn)練得分:{:.2f}".format(mlp.score(X_train,y_train)))
print("測試得分:{:.2f}".format(mlp.score(X_test,y_test)))
            
          

通過內(nèi)置紅酒數(shù)據(jù)集可畫出神經(jīng)網(wǎng)絡(luò)算法圖:

python--MLP神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)手寫數(shù)字識別_第1張圖片

將正則化參數(shù)恢復(fù)為默認(rèn)后:

mlp = MLPClassifier(solver = 'lbfgs',hidden_layer_sizes=[100,100],activation='tanh')

python--MLP神經(jīng)網(wǎng)絡(luò)實(shí)現(xiàn)手寫數(shù)字識別_第2張圖片

可見參數(shù)對效果的影響。

?

  • 實(shí)例--手寫識別

使用內(nèi)置數(shù)據(jù)集“l(fā)oad_digits

查看參數(shù):

            
              print(digits.keys())#數(shù)據(jù)集中的建
print(digits.data[0])#第一個(gè)數(shù)據(jù)
print(digits.target[0])#第一個(gè)數(shù)據(jù)的類型
print(digits.DESCR)#描述
            
          
            
              dict_keys(['data', 'target', 'target_names', 'images', 'DESCR'])
[ 0.  0.  5. 13.  9.  1.  0.  0.  0.  0. 13. 15. 10. 15.  5.  0.  0.  3.
 15.  2.  0. 11.  8.  0.  0.  4. 12.  0.  0.  8.  8.  0.  0.  5.  8.  0.
  0.  9.  8.  0.  0.  4. 11.  0.  1. 12.  7.  0.  0.  2. 14.  5. 10. 12.
  0.  0.  0.  0.  6. 13. 10.  0.  0.  0.]
0
.. _digits_dataset:

Optical recognition of handwritten digits dataset
--------------------------------------------------

**Data Set Characteristics:**

    :Number of Instances: 5620
    :Number of Attributes: 64
    :Attribute Information: 8x8 image of integer pixels in the range 0..16.
    :Missing Attribute Values: None
    :Creator: E. Alpaydin (alpaydin '@' boun.edu.tr)
    :Date: July; 1998

This is a copy of the test set of the UCI ML hand-written digits datasets
https://archive.ics.uci.edu/ml/datasets/Optical+Recognition+of+Handwritten+Digits

The data set contains images of hand-written digits: 10 classes where
each class refers to a digit.

Preprocessing programs made available by NIST were used to extract
normalized bitmaps of handwritten digits from a preprinted form. From a
total of 43 people, 30 contributed to the training set and different 13
to the test set. 32x32 bitmaps are divided into nonoverlapping blocks of
4x4 and the number of on pixels are counted in each block. This generates
an input matrix of 8x8 where each element is an integer in the range
0..16. This reduces dimensionality and gives invariance to small
distortions.

For info on NIST preprocessing routines, see M. D. Garris, J. L. Blue, G.
T. Candela, D. L. Dimmick, J. Geist, P. J. Grother, S. A. Janet, and C.
L. Wilson, NIST Form-Based Handprint Recognition System, NISTIR 5469,
1994.

.. topic:: References

  - C. Kaynak (1995) Methods of Combining Multiple Classifiers and Their
    Applications to Handwritten Digit Recognition, MSc Thesis, Institute of
    Graduate Studies in Science and Engineering, Bogazici University.
  - E. Alpaydin, C. Kaynak (1998) Cascading Classifiers, Kybernetika.
  - Ken Tang and Ponnuthurai N. Suganthan and Xi Yao and A. Kai Qin.
    Linear dimensionalityreduction using relevance weighted LDA. School of
    Electrical and Electronic Engineering Nanyang Technological University.
    2005.
  - Claudio Gentile. A New Approximate Maximal Margin Classification
    Algorithm. NIPS. 2000.
            
          

通過描述幸喜可以發(fā)現(xiàn)圖片為8*8的大小

完整代碼:

            
              #MNIST數(shù)據(jù)集
from sklearn.datasets import load_digits
digits = load_digits()
X=digits.data
y=digits.target
X_train,X_test,y_train,y_test = train_test_split(X,y,random_state=0)

mlp = MLPClassifier(solver = 'lbfgs',hidden_layer_sizes=[100,100],activation='relu',random_state=62)
mlp.fit(X_train,y_train)

print(X_train.shape,y_train.shape,X_test.shape,y_test.shape)
print("訓(xùn)練得分:{:.2f}".format(mlp.score(X_train,y_train)))
print("測試得分:{:.2f}".format(mlp.score(X_test,y_test)))
#導(dǎo)入圖像處理工具
from PIL import Image

image = Image.open('1.png').convert('F')
image = image.resize((8,8))
arr = []

for i in range(8):
    for j in range(8):
        pixel = 1.0 - float(image.getpixel((j,i)))/255
        arr.append(pixel)
        
arr1 = np.array(arr).reshape(1,-1)

for i in range(10):
    print('{}的概率為:{}'.format(i,mlp.predict_proba(arr1)[0][i]))
print('結(jié)果為:{}'.format(mlp.predict(arr1)[0]))
            
          

更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦?。。?/p>

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 一级毛片免费在线播放 | 免费在线视频一区 | 九九热精品视频在线观看 | 久久网国产| 夜夜cao| 另类综合视频 | 一本到在线观看视频不卡 | 色偷偷久久一区二区三区 | 超级碰碰青草久热国产 | 欧美专区亚洲专区 | 99久久久久国产 | 欧美亚洲综合图区在线 | 免费看爱爱视频 | 高级毛片 | 福利视频在线 | 国产女人精品性视频 | 一区二区三区www | 欧美成人私人视频88在线观看 | 伊人色婷婷综在合线亚洲 | 日韩在线手机看片免费看 | 青青久久99久久99久久999 | 欧美777精品久久久久网 | 亚洲精品国产成人99久久 | 麻豆国产精品高中生视频 | 中文日产国产精品久久 | 奇米影视在线视频8888 | 欧美性生交xxxxx久久久 | 亚洲va欧美va国产综合久久 | 国产精品久久久久久一区二区三区 | 国产成人亚洲精品91专区高清 | 天天干天天干天天色 | 久久精品国产精品亚洲 | 日韩美女中文字幕 | 免费激情片 | 青娱乐91在线 | 日本伊人色综合网 | 一级毛片人与动免费观看 | 毛片网页| 在线观看日本免费不卡 | 四虎免费在线视频 | 亚洲破处视频 |