Monday, February 20, 2017

liblinear使用

http://u.cs.biu.ac.il/~89-680/liblinear/using_liblinear.html


http://u.cs.biu.ac.il/~89-680/liblinear/liblin.py

看了上面的这篇介绍liblinear的文章,真是写的通俗易懂,更加深了自己对这个库的理解。进去网站,发现文字看不懂啊,百度了一下“巴伊兰大学1955年建于拉马特甘,是目前以色列第二大的学术机构。”


其中关于C惩罚

c越大越容易过拟合
c越小越容易欠拟合

关于惩罚项的具体公式和推倒还是要好好看看。



Q: How to select the regularization parameter C?
After version 2.0, an option -C is provided to find C. For example, you can run
> train -C data_file  
to find the C value with the best CV rate.


还有这篇文章

http://dataunion.org/15669.html

C和σ2对SVM的影响:
  • C较大(λ较小)时,可能会过拟合(Low bias, high variance);
  • C较小(λ较大)时,可能会欠拟合(High bias, low variance);
  • σ2较大时,High bias, low variance;
  • σ2较小时,Low bias, high variance;

Sunday, February 19, 2017

记录ConfigParser在Python2.6下一坑

import ConfigParser
import codecs
import os

#category_cfg_file="category.cfg"

category_cfg = ConfigParser.ConfigParser()
with codecs.open('feature_common.config', 'r',encoding='utf-8') as configfile:
    category_cfg.readfp(configfile)
   
   
features = category_cfg.sections()


上面代码在Python2.7下,返回的features顺序和配置文件中的顺序是一样的,可是服务器用的是Python2.7,这个返回的竟然是无序的,查到了很久才查到这一块。我草快被坑死了。

http://stackoverflow.com/questions/1134071/keep-configparser-output-files-sorted
找到答案,修复方法如下

In Python 2.7, you can from collections import OrderedDict and use ConfigParser(dict_type=OrderedDict) to make the parser use an ordered dictionary. Based on a minimal amount of testing, I think this should serve you well.

Wednesday, February 15, 2017

shell传参

http://stackoverflow.com/questions/415677/how-to-replace-placeholders-in-a-text-file

https://my.oschina.net/iuranus/blog/279985

Monday, February 13, 2017

安装mysqldb

##centos 环境
sudo yum install mysql-devel
sudo pip install mysql-python


##ubuntu环境
Starting with a vanilla Lucid install [1], install pip and upgrade to the latest version:
apt-get install python-pip
pip install -U pip
Next, install the required development packages:
apt-get install python-dev libmysqlclient-dev
then
pip install MySQL-python
should complete successfully.


mac下安装
$ brew uninstall mysql
$ brew install mysql-connector-c
$ brew unlink mysql-connector-c
$ brew install mysql
$ pip install mysql-python