搜索此博客

2016年7月26日星期二

How to load the {rJava} package after the error "JAVA_HOME cannot be determined from the Registry"

1、
下载jdk https://github.com/ojdkbuild/ojdkbuild

2、
Sys.setenv(JAVA_HOME='F:\\java-1.8.0-openjdk-1.8.0.101-1-ojdkbuild.b13.windows.x86_64\\jre')

library(rJava)

openjre 8 安装

sudo apt-get install openjdk-8-jre  openjdk-8-jdk

sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/ /usr/lib/jvm/default-java

openjre 8 安装

sudo apt-get install openjdk-8-jre  openjdk-8-jdk

sudo ln -s /usr/lib/jvm/java-8-openjdk-amd64/ /usr/lib/jvm/default-java

2016年7月17日星期日

MXnet在Linux下安装

1.sudo apt-get install -y build-essential git libblas-dev libopencv-dev libv8-dev librsvg2-dev libfftw3-dev libatlas-base-dev

2.git clone --recursive https://github.com/dmlc/mxnet

3.cd mxnet

  make -j4

4.Rscript -e "install.packages('devtools', repo = 'https://cran.rstudio.com')"
cd R-package
Rscript -e "library(devtools); library(methods); options(repos=c(CRAN='https://cran.rstudio.com')); install_deps(dependencies = TRUE)"
cd ..
make rpkg

R CMD INSTALL mxnet_0.7.tar.gz


参考:http://lchiffon.github.io/2015/11/06/install.html


错误Error in dyn.load(file, DLLpath = DLLpath, ...) :
  unable to load shared object '/home/xuefliang/R/x86_64-pc-linux-gnu-library/3.3/stringi/libs/stringi.so':
  libicui18n.so.52: cannot open shared object file: No such file or directory

解决:重新安装stringi包


TensorFlow安装配置

# Ubuntu/Linux 64-bit, CPU only, Python 2.7:
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

# Ubuntu/Linux 64-bit, GPU enabled, Python 2.7. Requires CUDA toolkit 7.5 and CuDNN v4.
# For other versions, see "Install from sources" below.
$ pip install --upgrade https://storage.googleapis.com/tensorflow/linux/gpu/tensorflow-0.8.0-cp27-none-linux_x86_64.whl

2016年7月4日星期一

anaconda2/lib/libreadline.so.6: undefined symbol: PC 错误处理

1、删除anaconda2/lib下
libreadline.a  libreadline.so.6.2 libreadline.so.6 libreadlin.so
2、pip install readline

参考
https://github.com/ContinuumIO/anaconda-issues/issues/42

jupyter notebook 中使用R

import rpy2
%load_ext rpy2.ipython

%%R 本cell中为R语言
%R 本行中为R语言

2016年7月2日星期六

Jupyter里面运行R

1、conda install -c r r-essentials
or
conda create -n my-r-env -c r r-essentials

2、建立一个~/Rnotebooks目录,进入后执行

source activate my-r-env

jupyter notebook

windows 安装 rpy2

1、下载rpy2 http://www.lfd.uci.edu/~gohlke/pythonlibs/#rpy2,

2016年7月1日星期五

tidyr学习

## 为方便处理,在数据集中增加一列car

```{r echo=FALSE,warning=FALSE,error=FALSE}
library(tidyr)
library(dplyr)
library(tibble)
head(mtcars)
mtcars$car <- rownames(mtcars)
mtcars <- mtcars[, c(12, 1:11)]
```

##gather-宽数据转为长数据,类似于reshape2包中的melt函数
```{r}
mtcarsNew <- mtcars%>%gather(attribute,value,-car)
#tidyr很好的一点是可以只gather若干列而其他列保持不变。如果你想gather在map和gear之间的所有列而保持carb和car列不变
mtcarsNew <- mtcars%>%gather(attribute,value,mpg:gear)
```

##spread—长数据转为宽数据,类似于reshape2包中的cast函数
```{r}
mtcarsSpread <- mtcarsNew%>%spread(attribute,value)
```

##unit—多列合并为一列
```{r}
set.seed(1)
date <- as.Date('2016-01-01') + 0:14
hour <- sample(1:24, 15)
min <- sample(1:60, 15)
second <- sample(1:60, 15)
event <- sample(letters, 15)
data <- data.frame(date, hour, min, second, event)

dataNew <- data%>%
  unite(datehour,date,hour,sep=' ')%>%
  unite(datetime,datehour,min,second,sep=':')
```


##separate—将一列分离为多列
```{r}
data1 <- dataNew%>%
  separate(datetime,c('date','time'),sep=' ')%>%
  separate(time,c('hour','min','second'),sep=':')

```

##separate_rows()通过分隔符将那些含有多个值的字段拆分为多行
```{r}
df <- data_frame(x = 1:2, y = c("a,b", "d,e,f"))
df %>%
  separate_rows(y, sep = ",")
```
对比separate()函数,它将df数据集拆分成了多列
```{r}
df %>%
  separate(y, c("y1", "y2", "y3"), sep = ",", fill = "right")
```

##spread()函数增加了一个sep参数:用于将列名设置为“key|sep|value”格式。这在对字段为数值型数据做重塑时非常有用。
```{r}
df <- data_frame(
  x = c(1, 2, 1),
  key = c(1, 1, 2),
  val = c("a", "b", "c")
)
df %>% spread(key, val)
df %>% spread(key, val, sep = "_")
```

##unnest()函数增加了一个.sep参数。当数据框的多个列包含有相同变量名的时候非常有用
```{r}
df <- data_frame(
  x = 1:2,
  y1 = list(
    data_frame(y = 1),
    data_frame(y = 2)
  ),
  y2 = list(
    data_frame(y = "a"),
    data_frame(y = "b")
  )
)
df %>% unnest()
df %>% unnest(.sep = "_")
```

###unnest()函数添加了.id参数用于显示列表中定义的名称
```{r}
df <- data_frame(
  x = 1:2,
  y = list(
    a = 1:3,
    b = 3:1
  )
)
df %>% unnest()
df %>% unnest(.id = "id")
```