我在R中使用标准stats
包在636,688行和7列的数据集上运行k-means聚类:kmeans(dataset, centers = 100, nstart = 25, iter.max = 20)
.
我收到以下错误:Quick-TRANSfer stage steps exceeded maximum (= 31834400)
,虽然人们可以在查看代码http://svn.r-project.org/R/trunk/src/library/stats/R/kmeans.R -我不确定的是什么出错了.我认为我的问题与我的数据集的大小有关,但如果有人能够一劳永逸地澄清我可以采取哪些措施来缓解这个问题,我将不胜感激.
我在 R 中运行 k-means 聚类,并希望NbClust
用于帮助确定最佳聚类数。我的数据集df
有 636,688 行和 7 列。
当我运行时NbClust(df, min.nc = 2, max.nc = 3, method = "kmeans")
,我得到:
Error: cannot allocate vector of size 1510.1 Gb
In addition: Warning messages:
1: In dist(jeu, method = "euclidean") :
Reached total allocation of 32767Mb: see help(memory.size)
2: In dist(jeu, method = "euclidean") :
Reached total allocation of 32767Mb: see help(memory.size)
3: In dist(jeu, method = "euclidean") :
Reached total allocation of 32767Mb: see help(memory.size)
4: …
Run Code Online (Sandbox Code Playgroud) 我正在大型数据集(636,688行x 7列)上执行k-均值,因此转向并行化。我的结果需要可重现。我可以用做clusterSetRNGStream
从parallel
包。这是一个使用库中Boston
数据集的示例MASS
:
library(parallel)
cl <- makeCluster(detectCores())
clusterSetRNGStream(cl, iseed = 1234)
clusterEvalQ(cl, library(MASS))
results <- clusterApply(cl, rep(25, 4), function(nstart) kmeans(Boston, 4, nstart = nstart))
check.results <- sapply(results, function(result) result$size)
stopCluster(cl)
Run Code Online (Sandbox Code Playgroud)
每check.results
列表示对于k-means算法的给定遍历,每个相应群集的观察次数。check.results
然后,我的样子如下:
[,1] [,2] [,3] [,4]
[1,] 38 268 102 102
[2,] 268 98 98 38
[3,] 98 102 38 268
[4,] 102 38 268 98
Run Code Online (Sandbox Code Playgroud)
如果将results
变量更改为include rep(25, 2)
而不是rep(25, 4)
,则会得到:
[,1] [,2]
[1,] 38 268 …
Run Code Online (Sandbox Code Playgroud) 我知道该emphasize.rownames
参数,但无法找到与列名称等效的参数。尝试调查panderOptions --> header.style
无济于事。
请在下面找到一些强调第一列而不是其标题的测试代码。理想情况下,我可以指定我想强调的列名,但是如果我至少可以强调整个标题,我会很高兴的。谢谢。
library(pander)
test = data.frame(Model = 1:3, Score = c(87,32,98), IQ = c(110,180,98))
# Print out the dataframe as a table using pander
pandoc.table(test, emphasize.strong.cols = 1)
Run Code Online (Sandbox Code Playgroud)
编辑
为了澄清-我期待创建使用PDF文档中的表格rmarkdown
,knitr
和pander
。这是示例代码-我希望强调标题,但是默认情况下,它不是我的机器上的代码:
---
title: "myexample"
output: pdf_document
---
```{r myexamp_setup, message = FALSE, echo=FALSE}
require(pander)
require(knitr)
test = data.frame(Model = 1:3, Score = c(87,32,98), IQ = c(110,180,98))
```
```{r myexamp_tab, echo = FALSE, results = 'asis'}
pandoc.table(test, emphasize.strong.cols = 1) …
Run Code Online (Sandbox Code Playgroud) 我期待创建使用PDF文档中的表格rmarkdown
,knitr
和pander
.该表应与下面的表1几乎相同,但星号应为子弹.这只是使用R
上面列出的库吗?
样本表http://i58.tinypic.com/16jlq13.png
这是我生成PDF文档的代码(以及上面的表格):
---
title: "xxx"
author: "xxx"
date: "xxx"
output:
word_document: default
pdf_document:
fig_height: 4
fig_width: 10
highlight: tango
geometry: margin=3cm
---
```{r global_options, include=FALSE, echo=FALSE}
require(knitr)
opts_chunk$set(fig.width=8, fig.height=4, fig.path='figs/', dpi=500,
echo=FALSE, warning=FALSE, message=FALSE, results='hide')
```
```{r pandoc_options, include=FALSE, echo=FALSE}
require(pander)
panderOptions('digits', 3)
panderOptions('round', 3)
panderOptions('keep.trailing.zeros', TRUE)
panderOptions('keep.line.breaks', TRUE)
```
```{r concepts, echo=FALSE}
mytable = data.frame(Concept = c("Decoded", "XXX"),
Description = c("
\\\n
\\\n * Founded in 2011
\\\n * * …
Run Code Online (Sandbox Code Playgroud)