예제 #1
0
 def test_ca(self):
     X, y = data1()
     self.assertAlmostEqual(solution.CA(y, [[1, 0]] * len(y)), 0.5)
     self.assertAlmostEqual(solution.CA(y, [[0.5, 1]] * len(y)), 0.5)
     self.assertAlmostEqual(solution.CA(y[:4], [[0.4, 0.6]] * len(y[:4])),
                            0.0)
     self.assertAlmostEqual(solution.CA(y[4:], [[0.4, 0.6]] * len(y[4:])),
                            1.0)
     self.assertAlmostEqual(solution.CA(y[:6], [[0.4, 0.6]] * len(y[:6])),
                            2 / 6.)
     self.assertAlmostEqual(
         solution.CA(y, [[0, 1], [0.2, 0.8], [0, 1], [0, 1], [1, 0],
                         [0.6, 0.4], [1, 0], [1, 0]]), 0.0)
예제 #2
0
    pylab.show()


X, y = solution.load('reg.data')

learner = solution.LogRegLearner(lambda_=0.)
classifier = learner(X, y)

draw_decision(X, y, classifier, 0, 1)

learner = solution.LogRegLearner(lambda_=0.01)
classifier = learner(X, y)

draw_decision(X, y, classifier, 0, 1)

learner = solution.LogRegLearner(lambda_=0.3)
classifier = learner(X, y)

draw_decision(X, y, classifier, 0, 1)

for lam in [0.0, 0.0001, 0.0005, 0.001, 0.01, 0.05, 0.1, 0.2, 0.3, 0.5]:
    learner = solution.LogRegLearner(lambda_=lam)
    res = solution.test_cv(learner, X, y)
    res1 = solution.test_learning(learner, X, y)
    print("Tocnost cv:", round(solution.CA(y, res),
                               3))  # argumenta sta pravi razredi, napovedani
    print("Tocnost learning:",
          round(solution.CA(y, res1),
                3))  # argumenta sta pravi razredi, napovedani
    print("\n")
예제 #3
0
 def test_logreg_noreg_learning_ca(self):
     X, y = data1()
     logreg = solution.LogRegLearner(lambda_=0)
     pred = solution.test_learning(logreg, X, y)
     ca = solution.CA(y, pred)
     self.assertAlmostEqual(ca, 1.)
예제 #4
0

# Part 3 test_cv:

X, y = s.load('reg.data')

lambdas = [10, 1, 0.5, 0.1, 0.075, 0.05, 0.03, 0.01, 0.001, 0.0001, 0.]

lambdas_ca = {l: 0 for l in lambdas}

for i in range(1,21):
    for l in lambdas:
        learner = s.LogRegLearner(lambda_=l)
        res = s.test_cv(learner, X, y, seed=i)

        ca = s.CA(y, res)

        lambdas_ca[l] += ca

for l in lambdas_ca.keys():
    print('Lambda:', l)
    print('Tocnost', lambdas_ca[l]/20)


# # Part 3 test_learning:
#
# X, y = s.load('reg.data')
#
# lambdas = [10, 1, 0.5, 0.1, 0.05, 0.03, 0.01, 0.001, 0.0001, 0.]
#
# lambdas_ca = {l: 0 for l in lambdas}