常見分類模型與算法
線性判別法
距離判別法
貝葉斯分類器
決策樹
支持向量機(SVM)
神經網絡
1.線性判別法
原理:用一條直線來划分學習集(這條直線不一定存在嗎?),然后根據待測點在直線的哪一邊決定它的分類
R語言實現:library(MASS)
ld=lda(G~x1+x2)
ld
2.距離判別法
原理:計算待測點與各類的距離,取最短者為其所屬分類
常用距離:
絕對值距離
歐氏距離
閔可夫斯基距離
切比雪夫距離
馬氏距離
Lance和Williams距離
離散變量的距離計算
各種類與類之間距離計算的方法
最短距離法
最長距離法
中間距離法
類平均法
重心法
離差平方和法
3.貝葉斯分類器
原理:
4.決策樹 decision tree
輸入:學習集
輸出:分類規則(決策樹)
R語言實現決策樹:rpart擴展包
以鳶尾花數據集作為算例說明:
iris.rp = rpart(Species~., data=iris, method="class")
plot(iris.rp, uniform=T, branch=0, margin=0.1, main=“ Classification Tree\nIris Species by Petal and Sepal Length")
text(iris.rp, use.n=T, fancy=T, col="blue")
Rule 1: if Petal.Length>=2.45&Petal.Width<1.75, then it is versicolor(0/49/5)
Rule 2: if Petal.Length>=2.45&Petal.Width>=1.75, then it is virginica (0/1/45)
Rule 3: if Petal.Length<2.45, then it is setosa (50/0/0)
結果:
5. Knn算法(k近鄰算法)
算法主要思想:
1 選取k個和待分類點距離最近的樣本點
2 看1中的樣本點的分類情況,投票決定待分類點所屬的類
6. 人工神經網絡(ANN=Artificial Neural Networks)
使用R語言實現人工神經網絡:
library(AMORE)
# P is the input vector
P <- matrix(sample(seq(-1,1,length=1000), 1000, replace=FALSE), ncol=1)
# The network will try to approximate the target P^2 target <- P^2
# We create a feedforward network, with two hidden layers.
# The first hidden layer has three neurons and the second has two neurons.
# The hidden layers have got Tansig activation functions and the output layer is Purelin. net <- newff(n.neurons=c(1,3,2,1), learning.rate.global=1e-2, momentum
.global=0.5, error.criterium="LMS", Stao=NA, hidden.layer="tansig", output.layer="purelin", method="ADAPTgdwm")
result <- train(net, P, target, error.criterium="LMS", report=TRUE, show.step=100, n.shows=5 )
y <- sim(result$net, P)
plot(P,y, col="blue", pch="+")
points(P,target, col="red", pch="x")
影響精度的因素:
訓練樣本數量
隱含層數與每層節點數。層數和節點太少,不能建立復雜的映射關系,預測誤差較大 。但層數和節點數過多,學習時間增加,還會產生“過度擬合”的可能。預測誤差隨 節點數呈現先減少后增加的趨勢。
激活函數的影響
神經網絡方法的優缺點
可以用統一的模式去處理高度復雜問題
便於元器件化,形成物理機器
中間過程無法從業務角度進行解釋
容易出現過度擬合問題
7.支持向量機 SVM
支持向量機,英文為Support Vector Machine,簡稱SV機。它是一種監督式學習的方法,它廣泛的應用於統計分類以及回歸分析中。支持向量機將向量映射到一個更高維的空間里,在這個空間里建立有一個最大間隔超平面。在分開數據的超平面的兩邊建有兩個互相平行的超平面,分隔超平面使兩個平行超平面的距離最大化。
優化目標:決策邊界邊緣距離最遠