`
insertyou
  • 浏览: 908579 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

Java程序通过weka调用libsvm的方法

 
阅读更多
<p class="MsoNormal" style="margin: 0cm 0cm 0pt;"><span lang="EN-US"><span style="font-size: small; font-family: Calibri;"></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span style="">在《</span><span class="title"><span lang="EN-US"><a href="http://blog.csdn.net/Felomeng/archive/2009/10/17/4688257.aspx" target="_blank"><span style="color: #0000ff;"><span style="" lang="EN-US"><span lang="EN-US">在</span></span><span style="font-family: Calibri;">eclipse</span><span style="" lang="EN-US"><span lang="EN-US">下使用</span></span><span style="font-family: Calibri;">java</span><span style="" lang="EN-US"><span lang="EN-US">调用</span></span><span style="font-family: Calibri;">weka</span></span></a></span></span><span class="title"><span style="">》的基础上,使用</span></span><span style="">《</span><span class="title"><span lang="EN-US"><a href="http://blog.csdn.net/Felomeng/archive/2009/10/17/4688257.aspx" target="_blank"><span style="color: #0000ff;"><span style="" lang="EN-US"><span lang="EN-US">在</span></span><span style="font-family: Calibri;">eclipse</span><span style="" lang="EN-US"><span lang="EN-US">下使用</span></span><span style="font-family: Calibri;">java</span><span style="" lang="EN-US"><span lang="EN-US">调用</span></span><span style="font-family: Calibri;">weka</span></span></a></span></span><span class="title"><span style="">》中介绍的方法添加</span><span lang="EN-US"><span style="font-family: Calibri;">libsvm</span></span></span><span class="title"><span style="">的两个</span><span lang="EN-US"><span style="font-family: Calibri;">jar</span></span></span><span class="title"><span style="">包(</span><span lang="EN-US"><span style="font-family: Calibri;">libsvm.jar</span></span></span><span class="title"><span style="">和</span><span lang="EN-US"><span style="font-family: Calibri;">wlsvm.jar</span></span></span><span class="title"><span style="">)及</span><span lang="EN-US"><span style="font-family: Calibri;">weka</span></span></span><span class="title"><span style="">的</span><span lang="EN-US"><span style="font-family: Calibri;">jar</span></span></span><span class="title"><span style="">包,这三个包可以从这里下载:</span><span lang="EN-US"><a href="http://download.csdn.net/source/1749854"><span style="color: #0000ff; font-family: Calibri;">http://download.csdn.net/source/1749854</span></a></span></span><span class="title"><span style="">。</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span class="title"><span style="">然后在</span><span lang="EN-US"><span style="font-family: Calibri;">import</span></span></span><span class="title"><span style="">诸语句下添加:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20.1pt;"><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">import</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> wlsvm.WLSVM;</span><span class="title"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span class="title"><span style="font-size: small;"><span style="">然后把原代码中的</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style=""> </span>Classifier m_classifier = </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">new</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> J48();</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span class="title"><span style="font-size: small;"><span style="">改为:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"><span style=""> </span>Classifier m_classifier = </span><strong><span style='font-size: 10pt; color: #7f0055; font-family: "Courier New";' lang="EN-US">new</span></strong><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US"> WLSVM();</span><span class="title"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span class="title"><span style="">然后运行就是使用</span><span lang="EN-US"><span style="font-family: Calibri;">SVM</span></span></span><span class="title"><span style="">分类了,当然,最后把输出句的</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">System.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">out</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">.println(</span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"J48 classification precision:"</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">+(right/sum));</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt; text-align: left;" align="left"><span style="">改为:</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt; text-align: left;" align="left"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">System.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">out</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">.println(</span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">""</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">);</span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">System.</span><em><span style='font-size: 10pt; color: #0000c0; font-family: "Courier New";' lang="EN-US">out</span></em><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">.println(</span><span style='font-size: 10pt; color: #2a00ff; font-family: "Courier New";' lang="EN-US">"SVM classification precision:"</span><span style='font-size: 10pt; color: black; font-family: "Courier New";' lang="EN-US">+(right/sum));</span><span class="title"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span class="title"><span lang="EN-US"><span style="font-size: small; font-family: Calibri;"></span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span style="font-size: small;"><span class="title"><span lang="EN-US"><span style="font-family: Calibri;">Libsvm</span></span></span><span class="title"><span style="">有一个问题就是内存占用比较大,经常会提示如下错误:</span></span></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 20pt;"><span style='font-size: 10pt; color: red; font-family: "Courier New";' lang="EN-US">java.lang.OutOfMemoryError: Java heap space</span><span class="title"></span></p>
<p class="MsoNormal" style="margin: 0cm 0cm 0pt; text-indent: 21pt;"><span class="title"><span style="font-size: small;"><span style="">在内存不足的情况下的确无法解决,但内存充足的话,可以配置一下程序所能占用的内存大小参数。设置方法:</span></span></span></p>
<p class="MsoListParagraph" style=""><span class="title"><span style="" lang="EN-US"><span style=""><span style="font-size: small; font-family: Calibri;">1.</span><span style='font: 7pt "Times New Roman";'> </span></span></span></span><span style="font-size: small;"><span class="title"><span style="">在</span><span lang="EN-US"><span style="font-family: Calibri;">Package Explorer</span></span></span><span class="title"><span style="">中选中调用</span><span lang="EN-US"><span style="font-family: Calibri;">libsvm</span></span></span><span class="title"><span style="">的类;</span></span></span></p>
<p class="MsoListParagraph" style=""><span class="title"><span style="" lang="EN-US"><span style=""><span style="font-size: small; font-family: Calibri;">2.</span><span style='font: 7pt "Times New Roman";'> </span></span></span></span><span style="font-size: small;"><span class="title"><span style="">在菜单中单击</span><span lang="EN-US"><span style="font-family: Calibri;">Run-&gt;run configuration…-&gt;</span></span></span><span class="title"><span style="">右面的</span><span lang="EN-US"><span style="font-family: Calibri;">(x=)arguments</span></span></span><span class="title"><span style="">页中的</span><span lang="EN-US"><span style="font-family: Calibri;">VM arguments</span></span></span><span class="title"><span style="">文本框中输入</span><span lang="EN-US"><span style="font-family: Calibri;">-Xmx1024M</span></span></span><span class="title"><span style="">。</span><span lang="EN-US"><span style="font-family: Calibri;">//</span></span></span><span class="title"><span style="">表示最大可使用</span><span lang="EN-US"><span style="font-family: Calibri;">1024M</span></span></span><span class="title"><span style="">内存,大家可以根据实际情况设置。</span></span></span></p>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics