def test_load(self):
     self.assertEqual(
         'File 123 loaded',
         solution.load('1', self.list_of_names_file1)
     )
     self.assertEqual(
         'There is no list with that index',
         solution.load('4', self.list_of_names_file1)
     )
 def test_load(self):
     list_of_orders = []
     dict_orders = {'dayana': 10}
     save(dict_orders, list_of_orders)
     save(dict_orders, list_of_orders)
     save(dict_orders, list_of_orders)
     self.assertEqual(2, load('1', list_of_orders, True))
     self.assertEqual(
         'You have unsaved order.' + '\n' + 'If you wish to discard the current order, type load again',
         load(10, list_of_orders, False)
     )
Esempio n. 3
0
            diff = points - numpy.array([x, y])
            dists = (diff[:, 0]**2 + diff[:, 1]**2)**0.5  #euclidean
            ind = numpy.argsort(dists)
            prob[yi, xi] = classifier(X[ind[0]])[1]

    pylab.imshow(prob, extent=(minx, maxx, maxy, miny))

    pylab.xlim(minx, maxx)
    pylab.ylim(miny, maxy)
    pylab.xlabel(at1)
    pylab.ylabel(at2)

    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)
 def test_load(self):
     self.assertEqual('File 123 loaded',
                      solution.load('1', self.list_of_names_file1))
     self.assertEqual('There is no list with that index',
                      solution.load('4', self.list_of_names_file1))
Esempio n. 5
0
            ind = np.argsort(dists)
            prob[yi, xi] = classifier(X[ind[0]])[1]

    pyplot.imshow(prob, extent=(minx, maxx, maxy, miny), cmap="seismic")

    pyplot.xlim(minx, maxx)
    pyplot.ylim(miny, maxy)
    pyplot.xlabel(at1)
    pyplot.ylabel(at2)
    pyplot.savefig(file_name + ".png")

    pyplot.show()


if __name__ == "__main__":
    X, y = load('./data/reg.data')

    # lambda_ = 0
    # learner = LogRegLearner(lambda_=0.)
    # classifier = learner(X, y)
    # draw_decision(X, y, classifier, 0, 1, file_name="lambda0")

    # learner = LogRegLearner(lambda_=10)
    # classifier = learner(X, y)
    # draw_decision(X, y, classifier, 0, 1, file_name="lambda1")
    #
    # learner = LogRegLearner(lambda_=0.01)
    # classifier = learner(X, y)
    # draw_decision(X, y, classifier, 0, 1, file_name="lambda3")
    #
    # learner = LogRegLearner(lambda_=0.0001)
Esempio n. 6
0
    for c, (x, y) in zip(y, points):
        pylab.text(x, y, str(c), ha="center", va="center")
        pylab.scatter([x], [y], c=["b", "r"][c != 0], s=200)

    num = grid
    prob = numpy.zeros([num, num])
    for xi, x in enumerate(numpy.linspace(minx, maxx, num=num)):
        for yi, y in enumerate(numpy.linspace(miny, maxy, num=num)):
            #probability of the closest example
            diff = points - numpy.array([x, y])
            dists = (diff[:, 0]**2 + diff[:, 1]**2)**0.5  #euclidean
            ind = numpy.argsort(dists)
            prob[yi, xi] = classifier(X[ind[0]])[1]
    pylab.imshow(prob, extent=(minx, maxx, maxy, miny))

    pylab.xlim(minx, maxx)
    pylab.ylim(miny, maxy)
    pylab.xlabel(at1)
    pylab.ylabel(at2)

    pylab.show()


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

learner = LogRegLearner(lambda_=0.1)
classifier = learner(X, y)

draw_decision(X, y, classifier, 0, 1)
Esempio n. 7
0
 def test_load(self):
     file_ = open("orders_0000_00_00_00_00_00", "w")
     file_.write("tester - 42.00")
     file_.close()
     result = solution.load(1, self.order)
     self.assertEqual({"tester": 42.00}, result)
Esempio n. 8
0
 def test_save_load(self):
     orders = {'Tyrion': '3.45', 'Kvothe': '4.62'}
     number_saves = 1
     solution.save(orders, number_saves)
     self.assertEqual({'Tyrion': '3.45', 'Kvothe': '4.62'}, solution.load("load 1"))
Esempio n. 9
0
#
# X, y = s.load('reg.data')
#
# lambdas = [10, 0.03, 0.]
#
# for i in lambdas:
#     learner = s.LogRegLearner(lambda_=i)
#     classifier = learner(X, y)
#
#
#     s.draw_decision(i, X, y, classifier, 0, 1)


# 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():
Esempio n. 10
0
test_cases = {
    'a=ab;d=c8\nln=21\n222=ool': [{
        'a': 'ab',
        'd': 'c8'
    }, {
        'ln': '21'
    }, {
        '222': 'ool'
    }],
    '': {},
    'lns=123\nsad-ew=213;nm=20312': [{
        'lns': '123'
    }, {
        'sad-ew': '213',
        'nm': '20312'
    }],
    '\n\nsds=12321\n\nsadsa=2132;b=c': [{}, {}, {
        'sds': '12321'
    }, {}, {
        'sadsa': '2132',
        'b': 'c'
    }]
}

for case, ans in test_cases.items():
    load_result = load(case)
    store_result = store(ans)

    assert load_result == ans, print(load_result, ans)
    assert load(store_result) == ans, print(store_result, case)