-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.py
89 lines (78 loc) · 3.43 KB
/
main.py
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
from imports import *
import dt
import knn
import perceptron
'''
Warming up to Classifiers
'''
# print('Always predict one: ')
runClassifier.trainTestSet(dumbClassifiers.AlwaysPredictOne({}), datasets.SentimentData)
# print('Always predict most frequent class: ', )
# runClassifier.trainTestSet(dumbClassifiers.AlwaysPredictMostFrequent({}), datasets.SentimentData)
# print('First Feature Classifier (Tennis Data):')
# runClassifier.trainTestSet(dumbClassifiers.FirstFeatureClassifier({}), datasets.TennisData)
# print('First Feature Classifier (SentimentData):')
# runClassifier.trainTestSet(dumbClassifiers.FirstFeatureClassifier({}), datasets.SentimentData)
'''
Decision Trees
'''
# h = dt.DT({'maxDepth': 5})
# h.train(datasets.TennisData.X, datasets.TennisData.Y)
# print(h)
'''
Running training and tests set
'''
# runClassifier.trainTestSet(dt.DT({'maxDepth': 1}), datasets.SentimentData)
# runClassifier.trainTestSet(dt.DT({'maxDepth': 3}), datasets.SentimentData)
# runClassifier.trainTestSet(dt.DT({'maxDepth': 5}), datasets.SentimentData)
'''
Better in terminal
'''
# curve = runClassifier.learningCurveSet(dt.DT({'maxDepth': 9}), datasets.SentimentData)
# runClassifier.plotCurve('DT on Sentiment Data', curve)
# curve = runClassifier.hyperparamCurveSet(dt.DT({}), 'maxDepth', [1,2,4,6,8,12,16], datasets.SentimentData)
# runClassifier.plotCurve('DT on Sentiment Data (hyperparameter)', curve)
'''
KNN
'''
'''
EPS
'''
# print('EPS:')
# runClassifier.trainTestSet(knn.KNN({'isKNN': False, 'eps': 0.5}), datasets.TennisData)
# runClassifier.trainTestSet(knn.KNN({'isKNN': False, 'eps': 1.0}), datasets.TennisData)
# runClassifier.trainTestSet(knn.KNN({'isKNN': False, 'eps': 2.0}), datasets.TennisData)
'''
KNN
'''
# print('KNN: ')
# runClassifier.trainTestSet(knn.KNN({'isKNN': True, 'K': 1}), datasets.TennisData)
# runClassifier.trainTestSet(knn.KNN({'isKNN': True, 'K': 3}), datasets.TennisData)
# runClassifier.trainTestSet(knn.KNN({'isKNN': True, 'K': 5}), datasets.TennisData)
# curveKNN = runClassifier.hyperparamCurveSet(knn.KNN({'isKNN':True, 'K':1}), 'K', [1,3,5,7], datasets.TennisData)
# runClassifier.plotCurve('KNN K=[1,3,5,7]', curveKNN)
#
# curveEps = runClassifier.hyperparamCurveSet(knn.KNN({'isKNN':False, 'eps':0.5}), 'eps',[0.5,1.0,1.5,2.0], datasets.TennisData)
# runClassifier.plotCurve('KNN eps=[1.0,1.5,2.0]', curveEps)
#
# learningCurveK = runClassifier.learningCurveSet(knn.KNN({'isKNN':True, 'K':5}), datasets.TennisData)
# runClassifier.plotCurve('KNN K=5', learningCurveK)
#
'''
The Perceptron
'''
# runClassifier.trainTestSet(perceptron.Perceptron({'numEpoch': 1}), datasets.TennisData)
# runClassifier.trainTestSet(perceptron.Perceptron({'numEpoch': 2}), datasets.TennisData)
#
# runClassifier.plotData(datasets.TwoDDiagonal.X, datasets.TwoDDiagonal.Y)
h = perceptron.Perceptron({'numEpoch': 200})
# h.train(datasets.TwoDDiagonal.X, datasets.TwoDDiagonal.Y)
# runClassifier.plotClassifier(array([ 7.3, 18.9]), 0.0)
#
# runClassifier.trainTestSet(perceptron.Perceptron({'numEpoch': 1}), datasets.SentimentData)
# runClassifier.trainTestSet(perceptron.Perceptron({'numEpoch': 2}), datasets.SentimentData)
exs = range(1,20)
curveP = runClassifier.hyperparamCurveSet(h, 'numEpoch', exs, datasets.SentimentData)
runClassifier.plotCurve('Perceptron on epoch=[1:20]', curveP)
learningCurveK = runClassifier.learningCurveSet(perceptron.Perceptron({'numEpoch': 5}), datasets.SentimentData)
runClassifier.plotCurve('Perceptron Learning on Sentiment', learningCurveK)