ML—感知機演算法(MATLAB)

來源:互聯網
上載者:User

華電北風吹

天津大學認知計算與應用重點實驗室

最後修改日期:2015/8/23


      感知機演算法屬於比較簡單的分類器演算法,但是跟羅吉斯迴歸和支援向量機一樣屬於構建分類超平面。

      不同的是感知機採用分錯的樣本與分類超平面的距離作為損失函數,下面的演算法基於隨機梯度下降法,採用非同步方式達到收斂狀態

function [w]=perceptionLearn(x,y,learningRate,maxEpoch)% Perception Learn Algorithm% x,y 一行為一個樣本,y取值{-1,+1}[m,n]=size(x);x=[ones(m,1) x];w=zeros(1,n+1);for epoch=1:maxEpoch    finish=true;    for samlendex=1:m        if sign(x(samlendex,:)*w')~=y(samlendex)            finish=false;            w=w+learningRate*y(samlendex)*x(samlendex,:)        end    end    if finish==true        break;    endend

測試函數:

clear;clc;x=[3,3;4,3;1,1];y=[1,1,-1];plot(x(1:2,1),x(1:2,2),'*');hold on;plot(x(3,1),x(3,2),'p');% [w]=LogisticRegression(x,y,1,20);[w]=perceptionLearn(x,y,1,20);xline=linspace(0,5,20);yline=-w(2)/w(3).*xline-w(1)/w(3);plot(xline,yline);

結果映像如下:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.