安装后添加没有class library_安装R的机器学习GUI工具rattle包

53b049c8e4490a275408d74d5d229fc1.png

这可是用R玩机器学习的利器。

8e0bfe3ce06ff7174f3aa9c402997151.png

安装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包作者你也太调皮啦

e58d012eeb7b5f846d1c7c35f84d88dc.png

运行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:UserschangAppDataLocalTempRtmpGibdawdownloaded_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+

910cbb6a7b22149947a0f4c2f7121833.png

说实话,R这套包管理系统还真是省心。需要什么,用到的时候现装就行。

92210bbd3458d44fa17227e5bfd271d9.png
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/gnome/binaries/win64/gtk+/2.22/gtk+-bundle2.22.1-20101229win64.zip 下载了安装包,解压放在了错误信息里面的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.2libraryRGtk2gtkx64' 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.2libraryRGtk2gtkx64etcgtk-2.0' already exists

1d6d6238cdefccecf365bf21c4cf7559.png

bdae57b62f4c1735e3b3a2733bfd0a78.png

启动rattle

> rattle()
Loading required package: RGtk2

cd40b9067837e9bd07aafab8fd312ad3.png

安装成功

用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
  • 执行按钮

4c3da3123f05de0a5a2642b56ec2fb33.png

结果

d9772e418399248ec88ffb80fc27a82b.png

改一下Partition,训练集、验证集和测试集的比例按照默认的70%,30%和0%,随机种子42。执行按钮

5c613519f852bd9ddaccdd03cc826c92.png
  • 点Model页
  • 类型选 Tree决策树
  • 选Conditional
  • 执行按钮

05317d1fad363daa5ff5096f0e9d6734.png

结果如下

没有结果,因为报错了……

安装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:UserschangAppDataLocalTempRtmpOUfyRkdownloaded_packages里

71f024843c17b78b18e6ab60017c8728.png

决策树-条件推断树

调整一下参数,再运行一次决策树的变体条件推断树

c5361a40d88200ebecfdad8490ff47f3.png

f9e20ac23310f65822d17d795b319ca4.png

顺利运行

5098a30181203555a0730ff5b69b7b0f.png

结果还不错

 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
======================================================================

点绘图按钮

8cfc83e296aaaa3a90d819e9fdd2bd34.png

这图没有直接绘制好看,但也不丑

3ae98a9d835e2ccb67e3847e5774e225.png

下一步可以看一下评价页

4a25c2320f9034d158de2f21be120c62.png
感谢阅读,欢迎关注和留言
量化投资与期货外汇散仙,基金保险水平也拿的出手
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
>