Libsvm的说明——方法

Utility Functions

=================

To use utility functions, type:

    >>> from svmutil import *

The above command loads:

    svm_train()            : train an SVM model

    svm_predict()          : predict testing data

    svm_read_problem()    : read the data from a LIBSVM-format file.

    svm_load_model()      : load a LIBSVM model.

    svm_save_model()      : save model to a file.

    evaluations()          : evaluate prediction results.

    csr_find_scale_param() : find scaling parameter for data in csr format(查找csr格式数据的缩放参数).

    csr_scale()            : apply data scaling to data in csr format(对csr格式的数据应用数据缩放).

## 第一个function

- ***Function: svm_train***

There are three ways to call svm_train()

    >>> model = svm_train(y, x [, 'training_options'])

    >>> model = svm_train(prob [, 'training_options'])

    >>> model = svm_train(prob, param)

    y: a list/tuple/ndarray of l training labels (type must be int/double).

    x: 1. a list/tuple of l training instances. Feature vector of each training instance is a list/tuple or dictionary.

      2. an l * n numpy ndarray or scipy spmatrix (n: number of features).

    training_options: a string in the same form as that for LIBSVM command mode.

    prob: an svm_problem instance generated by calling

          svm_problem(y, x).

          For pre-computed kernel, you should use

          svm_problem(y, x, isKernel=True)

    param: an svm_parameter instance generated by calling

          svm_parameter('training_options')

    model: the returned svm_model instance. See svm.h for details of this structure. If '-v' is specified, cross validation is

          conducted and the returned model is just a scalar: cross-validation accuracy for classification and mean-squared error for regression.

To train the same data many times with different  parameters, the second and the third ways should be faster..

  Examples:


    >>> y, x = svm_read_problem('../heart_scale')

    >>> prob = svm_problem(y, x)

    >>> param = svm_parameter('-s 3 -c 5 -h 0')

    >>> m = svm_train(y, x, '-c 5')

    >>> m = svm_train(prob, '-t 2 -c 5')

    >>> m = svm_train(prob, param)

    >>> CV_ACC = svm_train(y, x, '-v 3')

## 第二个function

***- Function: svm_predict***

    To predict testing data with a model, use

    >>> p_labs, p_acc, p_vals = svm_predict(y, x, model [,'predicting_options'])

    y: a list/tuple/ndarray of l true labels (type must be int/double).

      It is used for calculating the accuracy. Use [] if true labels are unavailable.

    x: 1. a list/tuple of l training instances. Feature vector of each training instance is a list/tuple or dictionary.

      2. an l * n numpy ndarray or scipy spmatrix (n: number of features).

    predicting_options: a string of predicting options in the same format as that of LIBSVM.

    model: an svm_model instance.

    p_labels: a list of predicted labels

    p_acc: a tuple including accuracy (for classification), mean squared error, and squared correlation coefficient (for regression)(包括准确度(用于分类)、均方误差和平方相关系数(用于回归)的元组).

    p_vals: a list of decision values or probability estimates (if '-b 1' is specified). If k is the number of classes in training data, for decision values, each element includes results of predicting k(k-1)/2 binary-class SVMs. For classification, k = 1 is a special case. Decision value [+1] is returned for each testing instance, instead of an empty list.

            For probabilities, each element contains k values indicating the probability that the testing instance is in each class. Note that the order of classes is the same as the 'model.label' field in the model structure.

Example:

    >>> m = svm_train(y, x, '-c 5')

    >>> p_labels, p_acc, p_vals = svm_predict(y, x, m)

## 第三组functions

***- Functions: svm_read_problem/svm_load_model/svm_save_model***

    See the usage by examples:

    >>> y, x = svm_read_problem('data.txt')

    >>> m = svm_load_model('model_file')

    >>> svm_save_model('model_file', m)

## 第四个functions

***- Function: evaluations***

Calculate some evaluations using the true values (ty) and the predicted values (pv):

    >>> (ACC, MSE, SCC) = evaluations(ty, pv, useScipy)

    ty: a list/tuple/ndarray of true values.

    pv: a list/tuple/ndarray of predicted values.

    useScipy: convert ty, pv to ndarray, and use scipy functions to do the evaluation

    ACC: accuracy(准确度).

    MSE: mean squared error(均方误差).

    SCC: squared correlation coefficient(平方相关系数).

## 第五组functions

***- Function: csr_find_scale_parameter/csr_scale***

Scale data in csr format.

    >>> param = csr_find_scale_param(x [, lower=l, upper=u])

    >>> x = csr_scale(x, param)

    x: a csr_matrix of data.

    l: x scaling lower limit; default -1.(缩放下限,默认-1)

    u: x scaling upper limit; default 1.(缩放上限,默认1)

    The scaling process is: x * diag(coef) + ones(l, 1) * offset'

    param: a dictionary of scaling parameters, where param['coef'] = coef and param['offset'] = offset.

    coef: a scipy array of scaling coefficients(系数).

    offset: a scipy array of scaling offsets(偏移).

Additional Information

======================

This interface was written by Hsiang-Fu Yu from Department of Computer Science, National Taiwan University. If you find this tool useful, please cite LIBSVM as follows Chih-Chung Chang and Chih-Jen Lin, LIBSVM : a library for support vector machines. ACM Transactions on Intelligent Systems and

Technology, 2:27:1--27:27, 2011. Software available at http://www.csie.ntu.edu.tw/~cjlin/libsvm

For any question, please contact Chih-Jen Lin <cjlin@csie.ntu.edu.tw>, or check the FAQ page: [http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html](http://www.csie.ntu.edu.tw/~cjlin/libsvm/faq.html).

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,189评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,577评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,857评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,703评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,705评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,620评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,995评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,656评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,898评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,639评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,720评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,395评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,982评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,953评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,195评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,907评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,472评论 2 342

推荐阅读更多精彩内容