简体   繁体   English

使用Python对LibSVM中的多项式内核进行交叉验证

[英]Cross validation for polynomial kernel in LibSVM, using Python

I am using LibSVM with Python. 我正在将LibSVM与Python结合使用。 Prior to building my classifier, I want to plot the average error of cross validation for different values of d and C to find the best (d, C) combination in terms of average accuracy. 在建立分类器之前,我想对dC不同值绘制交叉验证的平均误差,以求出就平均准确度而言最佳的(d, C)组合。 I wrote a Python script to cross-validate for a particular d, C value and the output for each of the ten iterations of my cross-validation appeared on the screen. 我编写了一个Python脚本来对特定的d, C值进行交叉验证d, C并且交叉验证的十次迭代中的每一个的输出都出现在屏幕上。 I have 2 problems now: 我现在有2个问题:

  1. How to write a Python script that takes in variables for d and C values as parameters in the svm_parameter function. 如何编写将dC值的变量作为svm_parameter函数中的参数的Python脚本。 svm_parameter('-d dval') gives the error: svm_parameter('-d dval')给出错误:

     ValueError : invalid literal for int() with base 10:dval 
  2. How to record the output data - I can't find a way to save the accuracy for each classification unless I manually copy it from the UNIX screen. 如何记录输出数据-除非从UNIX屏幕手动复制,否则我无法找到一种方法来保存每种分类的准确性。 Is there a way to access and save the output file? 有没有办法访问和保存输出文件?

Thank you. 谢谢。 I am new to Python. 我是Python的新手。

I strongly recommend to use the excellent sklearn library for your task. 我强烈建议您将出色的sklearn库用于您的任务。 It also has a wrapper for LibSVM (see svm.SVC ), but in addition gives you all the necessary tools for cross-validation , finding optimal d and C with grid-search , easy way to measure accuracy with the metrics module and a huge number of other useful tools. 它还有一个LibSVM的包装器(请参阅svm.SVC ),但除此之外, 它还提供了所有必要的交叉验证工具,通过网格搜索找到最佳d和C,使用度量模块轻松测量准确性的方法以及庞大的功能。其他有用工具的数量。

Regarding the valuerror, python attempts to cast the string dval into an integer. 关于valuerror,python尝试将字符串dval转换为整数。 You probably want to do something like svm_parameter('-d %s' % dval) , if dval is the variable holding the value of d . 如果dval是保存d值的变量,则可能要执行svm_parameter('-d %s' % dval)之类的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM