示例#1
0
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 09 00:57:33 2013

@author: Tejay Cardon
visualize pla
"""

from utils import points2weights
from pla import runPla
import numpy as np

sum = 0.0
runs = 10
d = 10
for i in range(0, runs):
    print "Running test # " + str(i)

    f = points2weights(np.random.random((2, 2)) * 2 - 1)
    x = np.insert(np.random.random((d, 2)) * 2 - 1, 0, np.ones((1, d)), axis=1)

    trainings, w = runPla(x, f, show=True)
    sum += trainings
print "Average of " + str(sum / runs) + " iterations"
示例#2
0
文件: p5.py 项目: tejaycar/mooc-lfd
@author: Tejay Cardon
HW2-5
"""

import numpy as np
import LinearRegression as lr
from utils import points2weights

wrongIn = 0.0
runs = 1000
d = 100

for i in range(0,runs):
    print "Running test # " + str(i)
    
    f = points2weights(np.random.random((2,2)) * 2 - 1)
    x = np.insert(np.random.random((d,2)) * 2 - 1,0,np.ones((1,d)), axis=1)
    truth = np.sign(np.dot(x,f))
    i,o,w = lr.runLR(x, truth)
    
    wrongIn += i
print "Average of " + str(wrongIn/runs) + " wrong in sample per run"
fractionWrong = (wrongIn/runs)/d
print "%f incorrect on average in sample"%(fractionWrong)

a = abs(fractionWrong - 0)
b = abs(fractionWrong - 0.001)
c = abs(fractionWrong - 0.01)
d = abs(fractionWrong - 0.1)

if min([a,b,c,d]) == a :