<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://replica.wiki.extremist.software/index.php?action=history&amp;feed=atom&amp;title=Machine_Learning%2Feasy.py</id>
	<title>Machine Learning/easy.py - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://replica.wiki.extremist.software/index.php?action=history&amp;feed=atom&amp;title=Machine_Learning%2Feasy.py"/>
	<link rel="alternate" type="text/html" href="https://replica.wiki.extremist.software/index.php?title=Machine_Learning/easy.py&amp;action=history"/>
	<updated>2026-04-04T07:11:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.39.13</generator>
	<entry>
		<id>https://replica.wiki.extremist.software/index.php?title=Machine_Learning/easy.py&amp;diff=11318&amp;oldid=prev</id>
		<title>ThomasLotze: Created page with &#039;&lt;pre&gt; #!/usr/bin/env python  import sys import os from subprocess import *  if len(sys.argv) &lt;= 1: 	print(&#039;Usage: %s training_file [testing_file]&#039; % sys.argv[0]) 	raise SystemExi…&#039;</title>
		<link rel="alternate" type="text/html" href="https://replica.wiki.extremist.software/index.php?title=Machine_Learning/easy.py&amp;diff=11318&amp;oldid=prev"/>
		<updated>2010-05-22T05:46:07Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;#039;&amp;lt;pre&amp;gt; #!/usr/bin/env python  import sys import os from subprocess import *  if len(sys.argv) &amp;lt;= 1: 	print(&amp;#039;Usage: %s training_file [testing_file]&amp;#039; % sys.argv[0]) 	raise SystemExi…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
&lt;br /&gt;
import sys&lt;br /&gt;
import os&lt;br /&gt;
from subprocess import *&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;lt;= 1:&lt;br /&gt;
	print(&amp;#039;Usage: %s training_file [testing_file]&amp;#039; % sys.argv[0])&lt;br /&gt;
	raise SystemExit&lt;br /&gt;
&lt;br /&gt;
# svm, grid, and gnuplot executable files&lt;br /&gt;
&lt;br /&gt;
is_win32 = (sys.platform == &amp;#039;win32&amp;#039;)&lt;br /&gt;
if not is_win32:&lt;br /&gt;
	svmscale_exe = &amp;quot;../svm-scale&amp;quot;&lt;br /&gt;
	svmtrain_exe = &amp;quot;../svm-train&amp;quot;&lt;br /&gt;
	svmpredict_exe = &amp;quot;../svm-predict&amp;quot;&lt;br /&gt;
	grid_py = &amp;quot;./grid.py&amp;quot;&lt;br /&gt;
else:&lt;br /&gt;
        # example for windows&lt;br /&gt;
	svmscale_exe = r&amp;quot;..\windows\svm-scale.exe&amp;quot;&lt;br /&gt;
	svmtrain_exe = r&amp;quot;..\windows\svm-train.exe&amp;quot;&lt;br /&gt;
	svmpredict_exe = r&amp;quot;..\windows\svm-predict.exe&amp;quot;&lt;br /&gt;
	grid_py = r&amp;quot;.\grid.py&amp;quot;&lt;br /&gt;
&lt;br /&gt;
assert os.path.exists(svmscale_exe),&amp;quot;svm-scale executable not found&amp;quot;&lt;br /&gt;
assert os.path.exists(svmtrain_exe),&amp;quot;svm-train executable not found&amp;quot;&lt;br /&gt;
assert os.path.exists(svmpredict_exe),&amp;quot;svm-predict executable not found&amp;quot;&lt;br /&gt;
assert os.path.exists(grid_py),&amp;quot;grid.py not found&amp;quot;&lt;br /&gt;
&lt;br /&gt;
train_pathname = sys.argv[1]&lt;br /&gt;
assert os.path.exists(train_pathname),&amp;quot;training file not found&amp;quot;&lt;br /&gt;
file_name = os.path.split(train_pathname)[1]&lt;br /&gt;
scaled_file = file_name + &amp;quot;.scale&amp;quot;&lt;br /&gt;
model_file = file_name + &amp;quot;.model&amp;quot;&lt;br /&gt;
range_file = file_name + &amp;quot;.range&amp;quot;&lt;br /&gt;
&lt;br /&gt;
if len(sys.argv) &amp;gt; 2:&lt;br /&gt;
	test_pathname = sys.argv[2]&lt;br /&gt;
	file_name = os.path.split(test_pathname)[1]&lt;br /&gt;
	assert os.path.exists(test_pathname),&amp;quot;testing file not found&amp;quot;&lt;br /&gt;
	scaled_test_file = file_name + &amp;quot;.scale&amp;quot;&lt;br /&gt;
	predict_test_file = file_name + &amp;quot;.predict&amp;quot;&lt;br /&gt;
&lt;br /&gt;
cmd = &amp;#039;%s -s &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot; &amp;gt; &amp;quot;%s&amp;quot;&amp;#039; % (svmscale_exe, range_file, train_pathname, scaled_file)&lt;br /&gt;
print(&amp;#039;Scaling training data...&amp;#039;)&lt;br /&gt;
Popen(cmd, shell = True, stdout = PIPE).communicate()	&lt;br /&gt;
&lt;br /&gt;
cmd = &amp;#039;%s -svmtrain &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot;&amp;#039; % (grid_py, svmtrain_exe, scaled_file)&lt;br /&gt;
print(&amp;#039;Cross validation...&amp;#039;)&lt;br /&gt;
f = Popen(cmd, shell = True, stdout = PIPE).stdout&lt;br /&gt;
&lt;br /&gt;
line = &amp;#039;&amp;#039;&lt;br /&gt;
while True:&lt;br /&gt;
	last_line = line&lt;br /&gt;
	line = f.readline()&lt;br /&gt;
	if not line: break&lt;br /&gt;
c,g,rate = map(float,last_line.split())&lt;br /&gt;
&lt;br /&gt;
print(&amp;#039;Best c=%s, g=%s CV rate=%s&amp;#039; % (c,g,rate))&lt;br /&gt;
&lt;br /&gt;
cmd = &amp;#039;%s -c %s -g %s &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot;&amp;#039; % (svmtrain_exe,c,g,scaled_file,model_file)&lt;br /&gt;
print(&amp;#039;Training...&amp;#039;)&lt;br /&gt;
Popen(cmd, shell = True, stdout = PIPE).communicate()&lt;br /&gt;
&lt;br /&gt;
print(&amp;#039;Output model: %s&amp;#039; % model_file)&lt;br /&gt;
if len(sys.argv) &amp;gt; 2:&lt;br /&gt;
	cmd = &amp;#039;%s -r &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot; &amp;gt; &amp;quot;%s&amp;quot;&amp;#039; % (svmscale_exe, range_file, test_pathname, scaled_test_file)&lt;br /&gt;
	print(&amp;#039;Scaling testing data...&amp;#039;)&lt;br /&gt;
	Popen(cmd, shell = True, stdout = PIPE).communicate()	&lt;br /&gt;
&lt;br /&gt;
	cmd = &amp;#039;%s &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot; &amp;quot;%s&amp;quot;&amp;#039; % (svmpredict_exe, scaled_test_file, model_file, predict_test_file)&lt;br /&gt;
	print(&amp;#039;Testing...&amp;#039;)&lt;br /&gt;
	Popen(cmd, shell = True).communicate()	&lt;br /&gt;
&lt;br /&gt;
	print(&amp;#039;Output prediction: %s&amp;#039; % predict_test_file)&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>ThomasLotze</name></author>
	</entry>
</feed>