美文网首页
【R】语言机器学习之核心包e1071

【R】语言机器学习之核心包e1071

作者: caokai001 | 来源:发表于2018-09-24 22:44 被阅读110次

知乎 https://zhuanlan.zhihu.com/p/25188759

https://zhuanlan.zhihu.com/p/32305137

plot(SVM_model)

一、R SVM

svm(formula,data=NULL,…,subset,na.action=na.omit,sacle=TRUE)

主要参数说明如下:

formula:分类模型形式,在第二个表达式中可以理解为y~x

即y相当于标签,x相当于特征(变量)

data:数据框。

subset:可以指定数据集的一部分作为训练数据。

na.cation:缺失值处理,默认为删除缺失数据。

scale:将数据标准化,中心化,使其均值为0,方差为1,将自动执行。

type:svm的形式。为:C-classification ,nu-classification,one-classification(for novelty detection) ,eps-regression, nu-regression 五种形式。后面两者为做回归时用到。默认为C分类器。

kernel:在非线性可分时,我们引入核函数来做。R中提供的核函数如下

线性核:

u'*v

多项式核:

(gamma*u'*v +coef0)^degree

高斯核:

exp(-gamma*|u-v|^2)

sigmoid核:

tanh(gamma*u'*v +coef0)

默认为高斯核。顺带说一下,在kernel包中可以自定义核函数。

degree:多项式核的次数,默认为3

gamma:除去线性核外,其他核的参数,默认为1/数据维数

coef0:多项式核与sigmoid核的参数,默认为0.

cost:C分类中惩罚项c的取值

nu:Nu分类,单一分类中nu的值

cross:做k折交叉验证,计算分类正确性。

https://www.ikddm.com/3093.html/

二、R语言机器学习之核心包e1071

R语言有很多包可以做机器学习(Machine Learning)的任务。机器学习的任务主要有有监督的学习方式和无监督的学习方式。

svm(formula,data=NULL,…,subset,na.action=na.omit,sacle=TRUE)

R代码

##第一步:载入mlbench的Glass数据集

if(!suppressWarnings(require(mlbench)))

{

install.packages('mlbench')

require(mlbench)

}

data(Glass, package="mlbench")

##第二步:数据集划分:训练集和测试集

index <- 1:nrow(Glass)

testindex <- sample(index, trunc(length(index)/3))

testset <- Glass[testindex,]

trainset <- Glass[-testindex,]

##第三步:构建SVM模型

svm.model <- svm(Type ~ ., data = trainset, cost = 100, gamma = 1)

##第四步:SVM模型应用到测试数据集

svm.pred <- predict(svm.model, testset[,-10])

##第五步:模型结果评估

##1混淆矩阵

table(pred = svm.pred,true= testset[,10])

##2计算Accuracy和Kappa值

classAgreement(table(pred = svm.pred,true= testset[,10]))

相关链接:

1 SVM算法:https://en.wikipedia.org/wiki/Support_vector_machine

2 NB分类器:https://en.wikipedia.org/wiki/Naive_Bayes_classifier

3 回归算法:https://en.wikipedia.org/wiki/Regression_analysis

4 e1071包说明文档:https://cran.r-project.org/web/packages/e1071/

https://blog.csdn.net/u013421629/article/details/77719775?tdsourcetag=s_pcqq_aiomsg

http://blog.jobbole.com/92021/?tdsourcetag=s_pcqq_aiomsg

https://blog.csdn.net/NIeson2012/article/details/51354284

https://zhuanlan.zhihu.com/p/32305137?utm_source=qq&utm_medium=social&utm_oi=869352697768329216

https://zhuanlan.zhihu.com/p/24468741?refer=The-Art-of-Data

https://www.cnblogs.com/luonet/p/4028990.html

https://www.ikddm.com/3125.html/

https://c3h3notes.wordpress.com/2010/10/25/r%E4%B8%8A%E7%9A%84libsvm-package-e1071-%E5%8F%83%E6%95%B8%E7%AF%87/

相关文章

网友评论

      本文标题:【R】语言机器学习之核心包e1071

      本文链接:https://www.haomeiwen.com/subject/vhxcoftx.html