Heim  >  Artikel  >  Datenbank  >  通过ggplot2

通过ggplot2

PHP中文网
PHP中文网Original
2016-06-07 15:06:521707Durchsuche

最近在学习Mahout的推荐算法,算法模型选定之后要对这些算法的效果进行评估,所以需要用到R的一些画图工具,这样给人的直观感受很好,跟领导汇报时也很有说服力。在网上参考了张丹的博客(http://blog.fens.me/hadoop-mahout-recommend-job/),在他的博客里有

 

   最近在学习Mahout的推荐算法,算法模型选定之后要对这些算法的效果进行评估,所以需要用到R的一些画图工具,这样给人的直观感受很好,跟领导汇报时也很有说服力。在网上参考了张丹的博客(http://blog.fens.me/hadoop-mahout-recommend-job/),在他的博客里有R软件画出的结果图,但是我看了看不知道是怎么画的。于是我参考了《R_Graph_Cookbook.pdf》,这本书很详细,写的非常好。

1、安装ggplot2插件包

install.packages("ggplot2")


2、将ggplot2加载到内存中

library(ggplot2)
library(lattice)     ##如果单单画这个图的话这个包好像不用加载进来


3、评估结果数据

通过ggplot2

4、把数据读入到valuator变量中

valuator=read.csv("F:\\learndocs\\mahout\\k-means\\evaluator.csv", header = FALSE, sep = ",", quote="\"", dec=".",fill = TRUE, comment.char="")


5、替换变量,用read.csv读入数据时,默认情况下列名是V1,V2,V3...

evaluator=data.frame('algorithm'=evaluator$V1,'precision'=evaluator$V2,'recall'=evaluator$V3)


6、画图

qplot(precision,recall,data=evaluator,col= as.factor(algorithm))

通过ggplot2


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn