def test_cv_shuffled(self): """Do not take folds in order - shuffle because data is frequently clustered """ _, y = data_iris() X = np.array([[i] for i in range(100)]) pred = solution.test_cv(DummyShuffleLearner(), X, y, k=4) self.assertIsNotNone(pred)
def test_cv(self): for X, y in [data1(), data2()]: pred = solution.test_cv(DummyCVLearner(), X, y, k=4) if len(y) == 8: # training data should have 6 instances self.assertEqual(pred[0][1], 6) if len(set([a for _, a in pred])) != 1 and len(y) % 4 == 0: raise FoldsNotEqualSize() signatures = [a for a, _ in pred] if len(set(signatures)) != len(y): raise NotAllTested() if signatures != list(map(lambda x: sum(list(x)), X)): raise MixedOrder()
def test_cv(self): for X, y in [data1(), data2()]: X_copy = X.copy() pred = test_cv(DummyCVLearner(), X, y, k=4) if len(y) == 8: # on the first DS training data should have 6 instances self.assertEqual(pred[0][1], 6) # on the dirst DS all folds should be of equal size if len(set([a for _, a in pred])) != 1: raise FoldsNotEqualSize() signatures = [a for a, _ in pred] if len(set(signatures)) != len(y): raise NotAllTested() if signatures != list(map(lambda x: sum(list(x)), X_copy)): raise MixedOrder()
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")
# # 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(): 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.]