Group work for a Monash Research Methods course

merged some changes

Silver-T b6892721 4c8cf3c8

+62 -11
+1 -3
mini_proj/Load_Images.py
··· 56 56 print("ERROR: Data may not be completely saved") 57 57 58 58 59 - def __main__(): 59 + if __name__ == "__main__": 60 60 # Paths to the Waldo images 61 61 waldo_path = 'waldo_data/64/waldo' 62 62 n_waldo_path = 'waldo_data/64/notwaldo' 63 63 64 64 gen_data(waldo_path, n_waldo_path) 65 - 66 - __main__()
+50
mini_proj/_image_classifier.py
··· 1 + class ImageClassifier: 2 + """Class to create an ImageClassifier from a regular classifier with 5 3 + methods that are common amongst classifiers. 4 + """ 5 + 6 + def __init__(self, clf, *args, **kwargs): 7 + self.clf = clf(*args, **kwargs) 8 + 9 + def fit(self, X, *args, **kwargs): 10 + X = X.reshape((len(X), -1)) 11 + return self.clf.fit(X, *args, **kwargs) 12 + 13 + def predict(self, X, *args, **kwargs): 14 + X = X.reshape((len(X), -1)) 15 + return self.clf.predict(X, *args, **kwargs) 16 + 17 + def score(self, X, *args, **kwargs): 18 + X = X.reshape((len(X), -1)) 19 + return self.clf.score(X, *args, **kwargs) 20 + 21 + def get_params(self, *args, **kwargs): 22 + return self.clf.get_params(*args, **kwargs) 23 + 24 + def set_params(self, **params): 25 + return self.set_params(**params) 26 + 27 + if __name__ == '__main__': 28 + 29 + # Import datasets, classifiers and performance metrics 30 + from sklearn import datasets, svm, metrics 31 + 32 + # The digits dataset 33 + digits = datasets.load_digits() 34 + 35 + n_samples = len(digits.images) 36 + data = digits.images 37 + 38 + # Create a classifier: a support vector classifier 39 + classifier = ImageClassifier(svm.SVC, gamma=0.001) 40 + 41 + # We learn the digits on the first half of the digits 42 + classifier.fit(data[:n_samples // 2], digits.target[:n_samples // 2]) 43 + 44 + # Now predict the value of the digit on the second half: 45 + expected = digits.target[n_samples // 2:] 46 + predicted = classifier.predict(data[n_samples // 2:]) 47 + 48 + print("Classification report for classifier %s:\n%s\n" 49 + % (classifier, metrics.classification_report(expected, predicted))) 50 + print("Confusion matrix:\n%s" % metrics.confusion_matrix(expected, predicted))
+8 -3
mini_proj/waldo_model.py
··· 8 8 from keras.layers import Dense, Dropout, Activation, Flatten, Input 9 9 from keras.layers import Conv2D, MaxPooling2D, ZeroPadding2D 10 10 from keras.models import Model 11 - from keras.layers.normalization import BatchNormalization 12 - from keras.utils import np_utils 11 + 12 + from sklearn import svm, tree, naive_bayes, ensemble 13 + from _image_classifier import ImageClassifier 14 + 13 15 from keras.optimizers import Adadelta 14 16 from keras.callbacks import ModelCheckpoint 15 - 16 17 from keras import backend as K 17 18 K.set_image_dim_ordering('th') 18 19 np.random.seed(7) ··· 58 59 59 60 ## Define model 60 61 model = FCN() 62 + svm_iclf = ImageClassifier(svm.SVC) 63 + tree_iclf = ImageClassifier(tree.DecisionTreeClassifier) 64 + naive_bayes_iclf = ImageClassifier(naive_bayes.GaussianNBd) 65 + ensemble_iclf = ImageClassifier(ensemble.RandomForestClassifier) 61 66 62 67 ## Define training parameters 63 68 epochs = 20 # an epoch is one forward pass and back propogation of all training data
+3 -5
wk11/week11.tex
··· 47 47 \text{otherwise }f(\_,\_,\_) & = & 0 48 48 \end{eqnarray*} 49 49 50 - \begin{figure}[H] 51 - \includegraphics[scale=0.55]{plots} 50 + \begin{figure}[ht] 51 + \includegraphics[scale=0.6]{plots} 52 52 \centering 53 - \captionsetup{width=0.80\textwidth} 54 53 \caption{Plots of the execution of the cellular automata with the different 55 54 updating methods. From top-left to top-right: Synchronous, Random 56 55 Independent, Random Order. From bottom-left to bottom-right: Clocked, ··· 131 130 the graphs showing the energy released from the system over time to 132 131 gauge how where the runaway reaction occurs. 133 132 134 - \begin{figure}[H] 133 + \begin{figure}[ht] 135 134 \includegraphics[scale=0.70]{plots2} 136 135 \centering 137 - \captionsetup{width=0.80\textwidth} 138 136 \caption{Plots of energy released over time. Each plot corresponds a 139 137 different density: 0\%, 5\%, 8\%, 10\%, 11\%, 12\%, 13\%, 15\%, 17\% and 20\%} 140 138 \label{fig:plot2}