spark集群搭建及介绍:敬请关注

数据集:http://pan.baidu.com/s/1sjYN7lF

总结:使用sparkR进行数据分析建模相比R大致有3-5倍的提升

查看原始数据集:通过iris数据集生成

[root@master data]#pwd

/data

[root@master data]#ls -lhsrt iris1g.txt

1.3G -rw-r--r-- 1root root 1.3G Feb 16 14:16 iris1g.txt

登录sparkR:

sparkR --masteryarn-client  --num-executors 15

#1、载入数据:47671650千万数据,耗时1.60118mins

> (time1 <-Sys.time())

[1] "2016-02-1810:04:08 CST"

> data_iris <-read.table("/data/iris1g.txt", stringsAsFactors=T, sep=",",header=T, comment="", quote=NULL, encoding="UTF-8")

> Sys.time() -time1

Time difference of1.60118 mins

#使用data.table中的fread读取数据:4000千万数据,耗时1.910114
mins

library(data.table)

(time1 <-Sys.time())

data_iris <- fread("D:\\R大数据集/iris1g.txt",stringsAsFactors=T, sep=",",
header=T, encoding="UTF-8")

Sys.time() - time1

#2、数据预处理

> dim(data_iris)

[1] 47671650        5

str(data_iris)

> str(data_iris)

'data.frame':        47671650obs. of  5 variables:

$ X.Sepal.Length.: num  5.1 4.9 4.7 4.6 5 5.4 4.6 5 4.4 4.9 ...

$ X.Sepal.Width. : num  3.5 3 3.2 3.1 3.6 3.9 3.4 3.4 2.9 3.1 ...

$ X.Petal.Length.: num  1.4 1.4 1.3 1.5 1.4 1.7 1.4 1.5 1.4 1.5 ...

$ X.Petal.Width. : num  0.2 0.2 0.2 0.2 0.2 0.4 0.3 0.2 0.2 0.1 ...

$ X.Species.     : Factor w/ 3 levels"\"setosa\"","\"versicolor\"",..: 1 1 11 1 1 1 1 1 1 ...

> names(iris)

[1]"Sepal.Length" "Sepal.Width"  "Petal.Length""Petal.Width" "Species"

>names(data_iris)

[1]"X.Sepal.Length." "X.Sepal.Width."  "X.Petal.Length.""X.Petal.Width."

[5]"X.Species."

>

>names(data_iris) <- names(iris)

>names(data_iris)

[1]"Sepal.Length" "Sepal.Width"  "Petal.Length""Petal.Width" "Species"

#3、创建训练集和測试集数据

library(caret)

#创建训练集和測试集数据:耗时6.402254 secs

> (time1 <-Sys.time())

[1] "2016-02-1810:10:35 CST"

> ind <-base:::sample(3, nrow(data_iris), prob=c(0.3, 0.2, 0.5), replace=T)

> train <-data_iris[ind==1, ]

> test <-data_iris[ind==2, ]

> Sys.time() -time1

Time difference of6.402254 secs

#使用createDataPartition导致内存溢出

#(time1 <-Sys.time())

#index <-createDataPartition(data$Species, nrow(data), p=0.7, list=F)

#Sys.time() - time1

#train <-data[index, ]

#test <-data[-index, ]

> dim(train)

[1] 14301827        5

> dim(test)

[1] 9533737       5

memory.size()

gc()

#4、建模

#1)随机森林

#library(randomForest)

#model <-randomForest(train$X.Species.~., data=train, ntree=50, nPerm=10, mtry=3,proximity=T, importance=T)

#随机森林建模导致内存溢出

#2)使用决策时间建模:1.891634
mins

library(party)

> (time1 <-Sys.time())

[1] "2016-02-1810:12:08 CST"

> model <-ctree(Species~., data=train)

> Sys.time() -time1

Time difference of

>print(object.size(model), units="Mb")

6372.7 Mb

#str(model)

> summary(model)

Length     Class       Mode

1 BinaryTree         S4

#5、预測

> (time1 <-Sys.time())

[1] "2016-02-1810:14:49 CST"

> pred <-predict(model, test)

> Sys.time() -time1

Time difference of36.58139 secs

#6、模型评估

table(pred,test$Species)

>mean(pred==test$Species)

[1] 1

>base:::table(pred, test$Species)

pred           "setosa""versicolor" "virginica"

"setosa"      3177256            0           0

"versicolor"        0     3178471           0

"virginica"         0            0     3178010

>library(gmodels)

>CrossTable(pred, test$Species)

Cell Contents

|-------------------------|

|                       N |

| Chi-squarecontribution |

|           N / Row Total |

|           N / Col Total |

|         N / Table Total |

|-------------------------|

Total Observationsin Table:  9533737

| test$Species

pred |     "setosa" |"versicolor" | "virginica" |    RowTotal |

-------------|--------------|--------------|--------------|--------------|

"setosa" |      3177256 |            0 |            0 |      3177256 |

| 4238091.601 |  1059271.517 |  1059117.882 |              |

|        1.000 |        0.000 |        0.000 |        0.333 |

|        1.000 |        0.000 |        0.000 |              |

|        0.333 |        0.000 |        0.000 |              |

-------------|--------------|--------------|--------------|--------------|

"versicolor"|            0 |      3178471 |            0 |      3178471 |

| 1059271.517 |  4236471.588 |  1059522.895 |              |

|        0.000 |        1.000 |        0.000 |        0.333 |

|        0.000 |        1.000 |        0.000 |              |

|        0.000 |        0.333 |        0.000 |              |

-------------|--------------|--------------|--------------|--------------|

"virginica" |            0 |            0 |      3178010 |      3178010 |

| 1059117.882 |  1059522.895 |  4237086.223 |              |

|        0.000 |        0.000 |        1.000 |        0.333 |

|        0.000 |        0.000 |        1.000 |              |

|        0.000 |        0.000 |        0.333 |              |

-------------|--------------|--------------|--------------|--------------|

Column Total |      3177256 |      3178471 |      3178010 |      9533737 |

|        0.333 |        0.333 |        0.333 |              |

-------------|--------------|--------------|--------------|--------------|

```

sparkR处理Gb级数据集的更多相关文章

  1. python编程之处理GB级的大型文件

    一般我们采取分块处理,一次处理固定大小的块. def read_in_chunks(file_obj,chunk_size): """Lazy function (gen ...

  2. VC++获取一个GB级大文件的字节大小

    常规的获得小文件(2.1GB以下)的字节大小可以使用ftell,函数 ftell 用于得到文件位置指针当前位置相对于文件首的偏移字节数.使用fseek函数后再调用函数ftell()就能非常容易地确定文 ...

  3. SQLite剖析之功能特性

    SQLite是遵守ACID的轻型数据库引擎,它包含在一个相对较小的C库中.它是D.RichardHipp创建的公有领域项目.不像常见的客户端/服务器结构范例,SQLite引擎不是一个与程序通信的独立进 ...

  4. HDFS主要特性和体系结构

    引言 Hadoop分布式文件系统(HDFS)被设计成适合运行在通用硬件(commodity hardware)上的分布式文件系统.它和现有的分布式文件系统有很多共同点.但同时,它和其他的分布式文件系统 ...

  5. 数据分析≠Hadoop+NoSQL,不妨先看完善现有技术的10条捷径(分享)

            Hadoop让大数据分析走向了大众化,然而它的部署仍需耗费大量的人力和物力.在直奔Hadoop之前,是否已经将现有技术推向极限?这里总结了对Hadoop投资前可以尝试的10个替代方案, ...

  6. 最受IT公司欢迎的50款开源软件

    文章来自:云头条编译 本文介绍了多款知名的开源应用软件,科技公司可以用它们来管理自己的 IT 基础设施.开发产品. 过去十年间,许多科技公司已开始畅怀拥抱开源.许多公司使用开源工具来运行自己的 IT ...

  7. 数据分析≠Hadoop+NoSQL

    数据分析≠Hadoop+NoSQL 目录(?)[+]           Hadoop让大数据分析走向了大众化,然而它的部署仍需耗费大量的人力和物力.在直奔Hadoop之前,是否已经将现有技术推向极限 ...

  8. 【RAC】RAC相关基础知识

    [RAC]RAC相关基础知识 1.CRS简介    从Oracle 10G开始,oracle引进一套完整的集群管理解决方案—-Cluster-Ready Services,它包括集群连通性.消息和锁. ...

  9. TensorFlow练习13: 制作一个简单的聊天机器人

    现在很多卖货公司都使用聊天机器人充当客服人员,许多科技巨头也纷纷推出各自的聊天助手,如苹果Siri.Google Now.Amazon Alexa.微软小冰等等.前不久有一个视频比较了Google N ...

随机推荐

  1. Python: PS 图像调整--黑白

    本文用Python 实现 PS 里的图像调整–黑白,PS 里的黑白并不是简单粗暴的将图像转为灰度图,而是做了非常精细的处理,具体的算法原理和效果图可以参考以前的博客: http://blog.csdn ...

  2. P 值(p value)与统计检验

    P 值是最常用的一个统计学指标,几乎统计软件输出结果都有P值. 统计学的观点,超过一定基准(比如 5%,其实是低于5%),就不能简单地认为这是偶然事件了,而是受到了外在的影响. 一般而言,为了确定从样 ...

  3. CentOS6.8下完全干净卸载mysql

    来源整理于 https://www.cnblogs.com/wanghuaijun/p/6398240.html 虚拟机CentOS6.8下 先执行命令查看目录是否存在mysql 文件夹:  cd  ...

  4. vue中的分页操作

    首先,先看分页的代码: 这里还需要进行操作: 1.分页操作主要传递俩个数据,total和pagenum,一个显示当前页面共有多少条数据,一个是翻页后的操作,看列表的数据能不能跟着改变,在进页面发送请求 ...

  5. require(): open_basedir restriction in effect. File

    新安装的 lnmp 环境,将项目放上报 require(): open_basedir restriction in effect. File 的错误! 错误日志显示,访问脚本不在 open_base ...

  6. NodeJS学习笔记 (14)URL查询字符串-querystring(ok)

    模块概述 在nodejs中,提供了querystring这个模块,用来做url查询参数的解析,使用非常简单. 模块总共有四个方法,绝大部分时,我们只会用到 .parse(). **.stringify ...

  7. vscode 调试vue.js程序

    npm install -g vue-cli                //安装vue-clivue init webpack projectName  //创建项目 1.Ctrl+~ 打开命令行 ...

  8. 洛谷1019 单词接龙 字符串dfs

    问题描述 单词接龙是一个与我们经常玩的成语接龙相类似的游戏,现在我们已知一组单词,且给定一个开头的字母,要求出以这个字母开头的最长的“龙”(每个单词都最多在“龙”中出现两次),在两个单词相连时,其重合 ...

  9. 容器配置https

    生成秘钥库 通过jdk的keytool工具生成秘钥库 keytool -genkeypair -alias "localhost" -keyalg "RSA" ...

  10. shell单引号屏蔽变量方法

    [goforit ~]$ name="玖零後大叔" [goforit~]$ echo $name 玖零後大叔 [goforit ~]$ echo "$name" ...