Friday, December 16, 2016

WINDOWS SUBSYSTEM使用中遇到的问题


  1. sudo: unable to resolve host OPTIMISTPRIME
解决方法:http://iamnotmyself.com/2016/07/13/windows-subsystem-for-linux-error-unable-to-resolve-host-2/

编辑/etc/hosts 加入一行127.0.0.1 OPTIMISTPRIME


2.安装redis-server遇到问题如下:
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: No such file or directory

此问题基本使用subsystem都会遇到
解决方法:
This is an issue that everyone will start seeing. We need to add something on this in our official docs.
As @nuclearmistake points out, udev is something that breaks in apt-get but the errors should not cause any issues in WSL. We have reached out to Canonical on this one asking for the best solution and they recommend the following changes:
Write the following to /usr/sbin/policy-rc.d
#!/bin/sh
exit 101
chmod +x /usr/sbin/policy-rc.d
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl
I have tried this one myself and it looks to work quite well.

参见https://github.com/Microsoft/BashOnWindows/issues/143

3.直接执行redis-server启动redis,起不来,使用sudo redis-server能够启动,但是redis-cli不能联通

方法如下:
执行sudo service redis-server start

参见:https://github.com/Microsoft/BashOnWindows/issues/365

jetbrains 激活

http://jetbrains.tencent.click
IntelliJ IDEA 2016.2.4


1. 到网站 http://idea.lanyus.com/ 获取注册码。
2.填入下面的license server:
  http://intellij.mandroid.cn/
  http://idea.imsxm.com/
  http://idea.iteblog.com/key.php
2017.3版本更新后2已失效,使用1吧,或者自行搭建授权服务器(1上有教程)
idea 还可以申请edu邮箱获取linsence key,有邮箱的可以尝试一下(可以尝试去注册免费的edu邮箱进行申请) https://www.jetbrains.com/zh/student/
http://idea.imsxm.com/
分类: idea

Wednesday, November 30, 2016

celery错误

使用celery发现如下错误,配置的一个虚拟环境中可以运行,但是root环境确不可以。通过卸载 redis-py,重新安装redis解决,感觉可能是其他插件的原因。目前没有重现,重现后再好好找找原因。错误记录如下:
[2016-11-30 10:47:49,779: CRITICAL/MainProcess] Unrecoverable error: TypeError("can_read() got an unexpected keyword argument 'timeout'",)
Traceback (most recent call last):
  File "/anaconda/lib/python2.7/site-packages/celery/worker/worker.py", line 203, in start
    self.blueprint.start(self)
  File "/anaconda/lib/python2.7/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/anaconda/lib/python2.7/site-packages/celery/bootsteps.py", line 370, in start
    return self.obj.start()
  File "/anaconda/lib/python2.7/site-packages/celery/worker/consumer/consumer.py", line 318, in start
    blueprint.start(self)
  File "/anaconda/lib/python2.7/site-packages/celery/bootsteps.py", line 119, in start
    step.start(parent)
  File "/anaconda/lib/python2.7/site-packages/celery/worker/consumer/consumer.py", line 584, in start
    c.loop(*c.loop_args())
  File "/anaconda/lib/python2.7/site-packages/celery/worker/loops.py", line 88, in asynloop
    next(loop)
  File "/anaconda/lib/python2.7/site-packages/kombu/async/hub.py", line 345, in create_loop
    cb(*cbargs)
  File "/anaconda/lib/python2.7/site-packages/kombu/transport/redis.py", line 1038, in on_readable
    self.cycle.on_readable(fileno)
  File "/anaconda/lib/python2.7/site-packages/kombu/transport/redis.py", line 337, in on_readable
    chan.handlers[type]()
  File "/anaconda/lib/python2.7/site-packages/kombu/transport/redis.py", line 670, in _receive
    while c.connection.can_read(timeout=0):
TypeError: can_read() got an unexpected keyword argument 'timeout'

Sunday, November 27, 2016

conda virtualenv

以前玩深度学习一直是用的theano和keras,做为谷粉不能不试一下大热的TensorFlow。首先安装起来。

TensorFlow的安装指南非常详细,我是python的anaconda环境,所以直接先创建一个新环境,创建前先更新一下conda
conda update conda
conda update anaconda
看一下目前计算机上有哪些环境
conda info --env
目前只有root环境,所以新建一个专门为TensorFlow的环境,并将root中的包克隆过来
conda create --name tensorflow --clone root
激活使用环境
source activate tensorflow
退出环境
source deactivate

使用pip来安装
pip install --ignore-installed --upgrade https://storage.googleapis.com/tensorflow/mac/tensorflow-0.8.0-py2-none-any.whl

然后我们可以使用jupyter notebook来启动,下面是两个最简单的示例。

网易云音乐ubuntu

sudo gdebi netease-cloud-music_1.0.0_amd64_ubuntu16.04.deb

huozhe
apt-get -f install

Wednesday, November 16, 2016

GibbsLDA++ 使用记录

之前在centos下编译成功了,但是现在用的是ubuntu 16.04报错了
错误如下:
make -C src/ -f Makefile all
make[1]: Entering directory '/media/fanyangfeng/windoc/lecom/lecomwork/auto_feedback/lda/GibbsLDA++-0.2/src'
g++ -c -o utils.o utils.cpp
utils.cpp: In static member function ‘static int utils::parse_args(int, char**, model*)’:
utils.cpp:69:28: error: ‘atof’ was not declared in this scope
      alpha = atof(argv[++i]);     
                            ^
utils.cpp:72:27: error: ‘atof’ was not declared in this scope
      beta = atof(argv[++i]);     
                           ^
utils.cpp:75:24: error: ‘atoi’ was not declared in this scope
      K = atoi(argv[++i]);     
                        ^
utils.cpp:78:29: error: ‘atoi’ was not declared in this scope
      niters = atoi(argv[++i]);     
                             ^
utils.cpp:81:31: error: ‘atoi’ was not declared in this scope
      savestep = atoi(argv[++i]);
                               ^
utils.cpp:84:29: error: ‘atoi’ was not declared in this scope
      twords = atoi(argv[++i]);
                             ^
utils.cpp: In static member function ‘static int utils::read_and_parse(std::__cxx11::string, model*)’:
utils.cpp:270:41: error: ‘atof’ was not declared in this scope
      pmodel->alpha = atof(optval.c_str());
                                         ^
utils.cpp:273:40: error: ‘atof’ was not declared in this scope
      pmodel->beta = atof(optval.c_str());
                                        ^
utils.cpp:276:37: error: ‘atoi’ was not declared in this scope
      pmodel->K = atoi(optval.c_str());
                                     ^
utils.cpp:279:37: error: ‘atoi’ was not declared in this scope
      pmodel->M = atoi(optval.c_str());
                                     ^
utils.cpp:282:37: error: ‘atoi’ was not declared in this scope
      pmodel->V = atoi(optval.c_str());
                                     ^
utils.cpp:285:41: error: ‘atoi’ was not declared in this scope
      pmodel->liter = atoi(optval.c_str());
                                         ^
Makefile:17: recipe for target 'utils.o' failed
make[1]: *** [utils.o] Error 1
make[1]: Leaving directory '/media/fanyangfeng/windoc/lecom/lecomwork/auto_feedback/lda/GibbsLDA++-0.2/src'
Makefile:2: recipe for target 'all' failed
make: *** [all] Error 2


在http://blog.sciencenet.cn/blog-425672-654209.html找到答案,解决办法
解决方法:
1). 在src/utill.cpp 文件头加入:
#include<stdio.h> #include<stdlib.h>
2). 在src/utill.h 文件头加入:
#include<stdlib.h>
3). 在src/lda.cp 文件头加入:
#include<stdio.h>
4). 重新make

Thursday, November 3, 2016

mysql导入数据,制定特定列的方式

I am running this MySQL command:
LOAD DATA LOCAL INFILE 'books.csv'
INTO TABLE BOOK (Book_id, @dummy, Title, Publisher_name, @dummy, @dummy)
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES;
I am getting an error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual 
that corresponds to your MySQL server version for the right syntax to use near 
'FIELDS TERMINATED BY '\t' LINES TERMINATED BY '\r\n' IGNORE 1 LINES' at line 3
What am I doing wrong here?
shareimprove this question

2 Answers

http://dev.mysql.com/doc/refman/5.6/en/load-data.html shows the syntax. The clause naming columns goes after the IGNORE clause.
LOAD DATA LOCAL INFILE 'books.csv'
  INTO TABLE BOOK 
FIELDS TERMINATED BY '\t'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES
(Book_id, @dummy, Title, Publisher_name, @dummy, @dummy);
shareimprove this answer

Tuesday, October 18, 2016

MySQL存储emoji表情报错

SET NAMES utf8mb4;
ALTER table table CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci;
SHOW VARIABLES WHERE Variable_name LIKE 'character\_set\_%' OR Variable_name LIKE 'collation%';
ALTER TABLE phone MODIFY COLUMN desc_title VARCHAR(1024)
    CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Tuesday, October 11, 2016

git push origin v0.1

git tag -a v0.1 -m "Relase version v0.1"
git push origin v0.1


Git 中的tag指向一次commit的id,通常用来给开发分支做一个标记,如标记一个版本号。
打标签
git tag -a v1.01 -m "Relase version 1.01"
注解:git tag 是打标签的命令,-a 是添加标签,其后要跟新标签号,-m 及后面的字符串是对该标签的注释。
提交标签到远程仓库
git push origin -tags
注解:就像git push origin master 把本地修改提交到远程仓库一样,-tags可以把本地的打的标签全部提交到远程仓库。
删除标签
git tag -d v1.01
注解:-d 表示删除,后面跟要删除的tag名字
删除远程标签
git push origin :refs/tags/v1.01
注解:就像git push origin :branch_1 可以删除远程仓库的分支branch_1一样, 冒号前为空表示删除远程仓库的tag。
查看标签
git tag
或者
git tag -l

Wednesday, August 31, 2016

谈谈sklearn中的准确率和召回率





        实际
        1         0
预测 1    760       290
   0    1937      12488

其中预测为正例 1050,预测为负例14425


我们很容易得到 上面的 0正确率为12488/14425   召回为12488/12778
1的正确率为 760/1050 召回为760/2697
结果跟上面的结果一致,可是下面的avg/total 怎么来的,百思不得其解

查到
http://stackoverflow.com/questions/31169874/what-does-the-last-raw-mean-in-classification-report-in-scikit-learn

http://scikit-learn.org/stable/modules/generated/sklearn.metrics.precision_recall_fscore_support.html

http://stats.stackexchange.com/questions/117654/what-does-the-numbers-in-the-classification-report-of-sklearn-mean

源码如下:
# compute averages
values = [last_line_heading]
for v in (np.average(p, weights=s),
          np.average(r, weights=s),
          np.average(f1, weights=s)):
    values += ["{0:0.{1}f}".format(v, digits)]
values += ['{0}'.format(np.sum(s))]


原来是加权平均出来的
like this
准确率 =(0.87*12778+0.72*2697)/(12778+2697)
召回率 =(0.98*12778+0.28*2697)/(12778+2697)
也是醉了

Wednesday, August 24, 2016

shiny应用的开发与部署

shiny server的安装可以参见官方文档
具体说下遇见的问题

1.shiny表格乱码的情况,因为使用的是shiny的DT包,找到相关的文档,谢大神给出的答案是library(htmltools),windows下可以在.Rprofile文件中添加Sys.setlocale(, 'Chinese')

2.shiny中使用ggplot2,坐标,图例和图内文字显示为乱码

首先想到的是编码问题,参照了http://blog.csdn.net/wlwlwlwl015/article/details/51482065 的方法折腾一晚上,没有搞定。早上的时候看到了http://cos.name/cn/topic/408656/ 但是不知道这段话该放在哪里,最终回到谢大神这里,windows测试没有问题,放在centos下还是挂掉了,查看
http://shiny.rstudio.com/gallery/unicode-characters.html


错误跑出的异常是
sh: locate: command not found
rm(font_home)
downloaded 0 bytes

Error in utils::download.file(url, method = method, ...) : 
  cannot download all files
In addition: Warning message:
In utils::download.file(url, method = method, ...) :
  URL 'https://github-cloud.s3.amazonaws.com/releases/13722949/aca3ad44-1298-11e4-9499-2c2c4b1a1e74.ttc?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAISTNZFOVBIJMK3TQ%2F20160824%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20160824T024339Z&X-Amz-Expires=300&X-Amz-Signature=657ebda9fa7aec563592de13c160420b4013027a15f607a667a9e93159c2d7af&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Dwqy-zenhei.ttc&response-content-type=application%2Foctet-stream': status was '403 Forbidden


因为是内网环境,所以是没有配置代理的原因 ,R中设置代理的方法是
Sys.setenv(http_proxy="http://ip:port ″)

但是这个只对终端打开有效,线上的app还是不能用怎么办
分析了谢大的这段代码
font_home <- function(path = '') file.path('~', '.fonts', path)
if (Sys.info()[['sysname']] == 'Linux' &&
      system('locate wqy-zenhei.ttc') != 0 &&
      !file.exists(font_home('wqy-zenhei.ttc'))) {
  if (!file.exists('wqy-zenhei.ttc'))
    shiny:::download(
      'https://github.com/rstudio/shiny-examples/releases/download/v0.10.1/wqy-zenhei.ttc',
      'wqy-zenhei.ttc'
    )
  dir.create(font_home())
  file.copy('wqy-zenhei.ttc', font_home())
  system2('fc-cache', paste('-f', font_home()))
}
rm(font_home)
其实跟上面csdn博客中做的工作是类似的,既然访问不了github,那就下载传上去,然后执行这段命令,神奇般的能够显示了。
3.log地址 /var/log/shiny-server
4.部署:app文件放在/srv/shiny-server路径下就可以了

安装如下:
https://www.rstudio.com/products/shiny/download-server/

sudo yum install R
sudo su - \
-c "R -e \"install.packages('shiny', repos='https://cran.rstudio.com/')\""
$ wget https://download3.rstudio.org/centos5.9/x86_64/shiny-server-1.5.3.838-rh5-x86_64.rpm
$ sudo yum install --nogpgcheck shiny-server-1.5.3.838-rh5-x86_64.rpm


http://docs.rstudio.com/shiny-server/

管理:
$ sudo start shiny-server
$ sudo stop shiny-server
To restart the server you can run:
$ sudo stop shiny-server
$ sudo start shiny-server

Friday, August 19, 2016

删除docker



How to Remove Docker Images and Containers


In our previous tutorials you have learned about installation of Docker engine on CentOS/RHELand Ubuntu operating system and pulled images from Docker hub. After that created containers with images. This tutorial will help you to remove unnecessary Docker images and containers from your host machine.

Remove Docker Images

To remove an images, Docker provides rmi option. Using this we can delete any docker images from our local system. For example use below command with changing <IMAGE ID> with your Docker image id.
# docker rmi  <IMAGE ID>
To find all images on your system use following command. This will help you to find ID of images.
root@tecadmin:~# docker images

REPOSITORY     TAG        IMAGE ID            CREATED          VIRTUAL SIZE
centos         latest     2933d50b9f77        11 days ago      196.6 MB
ubuntu         latest     36248ae4a9ac        11 days ago      188 MB

Remove Docker Containers

To remove a containers, Docker provides rm option. Using this we can delete any docker containers from our local system. For example use below command with changing <CONTAINER ID> with your Docker container id.
# docker rm  <CONTAINER ID>
To list all containers on your system using ps option, but ps will show only running containers. So to view all containers use -a parameter with ps.
root@tecadmin:~# docker ps -a

CONTAINER ID   IMAGE    COMMAND      CREATED       STATUS      PORTS  NAMES
f2582758af13   ubuntu   "/bin/bash"  2 hours ago   Up 2 hours         first_ubuntu
2b199b9976c4   centos   "/bin/bash"  3 days ago    Up 3 hours         thirsty_yalow

Stop & Remove All Docker Containers

If you want to remove all docker containers. You can use simply following commands. First command will stop all running docker containers and second command will delete them.
# docker stop $(docker ps -a -q)
# docker rm $(docker ps -a -q)