File: python3-simple

package info (click to toggle)
liblinear 2.43%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 548 kB
  • sloc: cpp: 3,425; ansic: 2,138; python: 758; makefile: 90; sh: 41
file content (47 lines) | stat: -rw-r--r-- 1,372 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# Run a simple test from upstream's README for Python 3 against all requested
# Python 3 versions. Assumes $AUTOPKGTEST_TMP is set, see
# /usr/share/doc/autopkgtest/README.package-tests.rst.gz

SOURCE_BASE="$PWD"
for interpreter in `py3versions -r 2>/dev/null`
do
	echo "=== Testing with $interpreter ==="
	mkdir "$AUTOPKGTEST_TMP"/$interpreter
	cp "$SOURCE_BASE"/heart_scale "$AUTOPKGTEST_TMP/$interpreter"
	cd "$AUTOPKGTEST_TMP"/$interpreter

cat > lowlevel-test.py <<EOF
from liblinear.liblinear import *

prob = problem([1,-1], [{1:1, 3:1}, {1:-1,3:-1}])
param = parameter('-c 4')
m = liblinear.train(prob, param) # m is a ctype pointer to a model
# Convert a Python-format instance to feature_nodearray, a ctypes structure
x0, max_idx = gen_feature_nodearray({1:1, 3:1})
label = liblinear.predict(m, x0)
EOF

cat > util-test.py <<EOF
from liblinear.liblinearutil import *

# Read data in LIBSVM format
y, x = svm_read_problem('heart_scale')
m = train(y[:200], x[:200], '-c 4')
p_label, p_acc, p_val = predict(y[200:], x[200:], m)

# Construct problem in python format (Sparse data)
y, x = [1,-1], [{1:1, 3:1}, {1:-1,3:-1}]
prob  = problem(y, x)
param = parameter('-s 0 -c 4 -B 1')
m = train(prob, param)
EOF

	echo "--- Testing lowlevel API ---"
	$interpreter lowlevel-test.py
	echo

	echo "--- Testing util API ---"
	$interpreter util-test.py
	echo
done