这可是用R玩机器学习的利器。
安装rattle()包
> install.packages("rattle")
> library(rattle)
Rattle: A free graphical interface for data science with R.
XXXX 5.3.0 Copyright (c) 2006-2018 Togaware Pty Ltd.
键入'rattle()'去轻摇、晃动、翻滚你的数据。
rattle包作者你也太调皮啦
运行rattle()
安装RGtk2包
> rattle()
Error in rattle() :
The RGtk2 package is not available but is required.
Please install the package using, for example:
install.packages("RGtk2")
> install.packages(RGtk2)
Error in install.packages : object 'RGtk2' not found
> install.packages("RGtk2")
trying URL 'https://mirrors.tongji.edu.cn/CRAN/bin/windows/contrib/3.6/RGtk2_2.20.36.zip'
Content type 'application/zip' length 16558916 bytes (15.8 MB)
downloaded 15.8 MB
package ‘RGtk2’ successfully unpacked and MD5 sums checked
The downloaded binary packages are in
C:\Users\chang\AppData\Local\Temp\RtmpGibdaw\downloaded_packages
安装GTK+
再次启动rattle()
> rattle()
Loading required package: RGtk2
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'E:/R-3.6.2/library/RGtk2/libs/x64/RGtk2.dll':
LoadLibrary failure: 找不到指定的模块。
我的机器里没有装GTK,不过不用费心。Rattle发现了这个问题,直接问我是否安装GTK+
说实话,R这套包管理系统还真是省心。需要什么,用到的时候现装就行。
trying URL 'http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip'
Error: package or namespace load failed for ‘RGtk2’:
.onLoad failed in loadNamespace() for 'RGtk2', details:
call: download.file(dep_url, path, mode = "wb")
error: cannot open URL 'http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip'
Error in inDL(x, as.logical(local), as.logical(now), ...) :
unable to load shared object 'E:/R-3.6.2/library/RGtk2/libs/x64/RGtk2.dll':
LoadLibrary failure: 找不到指定的模块。
In addition: Warning messages:
1: Failed to load RGtk2 dynamic library, attempting to install it.
2: In download.file(dep_url, path, mode = "wb") :
InternetOpenUrl failed: '服务器返回无效或不可识别的响应'
trying URL 'http://ftp.gnome.org/pub/gnome/binaries/win64/gtk+/2.22/gtk+-bundle_2.22.1-20101229_win64.zip'
Content type 'application/zip' length 25830230 bytes (24.6 MB)
唉,和这种洋人的服务器关系依旧不太好。我自己从http://ftp.gnome.org/pub/gnom... 下载了安装包,解压放在了错误信息里面的E:R-3.6.2libraryRGtk2gtkx64文件夹里面。
In addition: Warning messages:
1: Failed to load RGtk2 dynamic library, attempting to install it.
2: In download.file(dep_url, path, mode = "wb") :
downloaded length 24694784 != reported length 25830230
3: In dir.create(gtk_path, recursive = TRUE) :
'E:\R-3.6.2\library\RGtk2\gtk\x64' already exists
4: In unzip(path, exdir = gtk_path) : error 1 in extracting from zip file
5: In dir.create(config_path, recursive = TRUE) :
'E:\R-3.6.2\library\RGtk2\gtk\x64\etc\gtk-2.0' already exists
启动rattle
> rattle()
Loading required package: RGtk2
安装成功
用rattle进行数据挖掘
载入案例数据印第安人糖尿病数据
> diabetes <- read.table(file="pima-indians-diabetes.data", sep="\t", header=FALSE)
> names(diabetes) <-c("npregant","plasma","bp","triceps","insulin","bmi","pedigree","age","class")
> diabetes$class <- factor(diabetes$class,levels = c(0,1),labels = c("normal","diabetic"))
启动rattle
> library(rattle)
> rattle()
- Data页面
- 选择数据来源:R Dataset
- Data Name选diabetes数据集
- 勾选Partition,训练集、验证集和测试集的比例按照默认的70%,15%和15%,随机种子42
- 执行按钮
结果
改一下Partition,训练集、验证集和测试集的比例按照默认的70%,30%和0%,随机种子42。执行按钮
- 点Model页
- 类型选 Tree决策树
- 选Conditional
- 执行按钮
结果如下
没有结果,因为报错了……
安装multcomp包
系统报错,说却少包multcomp
Error: package or namespace load failed for ‘party’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]):
there is no package called ‘multcomp’
本来觉得不难,直接安装
> install.packages("multcomp")
There is a binary version available but the source version is later:
binary source needs_compilation
multcomp 1.4-11 1.4-12 FALSE
installing the source package ‘multcomp’
trying URL 'https://mirrors.tongji.edu.cn/CRAN/src/contrib/multcomp_1.4-12.tar.gz'
Warning in install.packages :
cannot open URL 'https://mirrors.tongji.edu.cn/CRAN/src/contrib/multcomp_1.4-12.tar.gz': HTTP status was '404 Not Found'
Error in download.file(url, destfile, method, mode = "wb", ...) :
cannot open URL 'https://mirrors.tongji.edu.cn/CRAN/src/contrib/multcomp_1.4-12.tar.gz'
Warning in install.packages :
download of package ‘multcomp’ failed
居然同济大学的镜像中没有这个包……
从RGui进入,直接安装,选兰州 拉面 镜像。稍等,搞定。
> install.packages("multcomp")
--- 在此連線階段时请选用CRAN的鏡子 ---
试开URL’https://mirror.lzu.edu.cn/CRAN/bin/windows/contrib/3.6/multcomp_1.4-12.zip'
Content type 'application/zip' length 736891 bytes (719 KB)
downloaded 719 KB
程序包‘multcomp’打开成功,MD5和检查也通过
下载的二进制程序包在
C:\Users\chang\AppData\Local\Temp\RtmpOUfyRk\downloaded_packages里
# 决策树-条件推断树
调整一下参数,再运行一次决策树的变体条件推断树
顺利运行
结果还不错
Summary of the Conditional Tree model for XXXX (built using 'ctree'):
Conditional inference tree with 6 terminal nodes
Response: class
Inputs: npregant, plasma, bp, triceps, insulin, bmi, pedigree, age
Number of observations: 537
1) plasma <= 127; criterion = 1, statistic = 122.668
2) age <= 28; criterion = 1, statistic = 19.178
3) pedigree <= 0.493; criterion = 0.984, statistic = 9.494
4)* weights = 128
3) pedigree > 0.493
5)* weights = 60
2) age > 28
6)* weights = 148
1) plasma > 127
7) plasma <= 165; criterion = 1, statistic = 20.664
8) bmi <= 29.9; criterion = 0.999, statistic = 14.334
9)* weights = 55
8) bmi > 29.9
10)* weights = 91
7) plasma > 165
11)* weights = 55
Time taken: 0.03 secs
Rattle timestamp: 2020-02-02 17:20:50 chang
======================================================================
点绘图按钮
这图没有直接绘制好看,但也不丑
下一步可以看一下评价页
感谢阅读,欢迎关注和留言> 感谢阅读,欢迎关注和留言
量化投资与期货外汇散仙,基金保险水平也拿的出手