def classify_image(image)
#some magic here?
return class_label
data-driven approachdef train(images,labels):
#machine learning!
return model
def predict(model, test_images):
#use model to predict labels
return(test_labels)
first classifer: nearest neighbors
drawback: qucik training time, long predict time
distance metric to compare images
-L1 distance (Manhattan distance) reply on coordiante system you choose/ if the individual entries have important mearnings for your task
-L2 distance (Euclidean distance) don’t reply on coordiante you choose - it’s circle/ if only generic vector and don’t know which of the different elements
-good to try first
K-Nearest Neighbors
instead of copying label from nearest neighbor, take majority vote from K cosest points
expect use k>1, smooth out decision boundaries
hyperparameters- choices about the algorithm that we set rather than learn
-what is the best value of k to use?
-what is the best distance to use?
-idea1: work best on data ❌(bad: k=1 always works perfectly on training data)
-idea2: split your data into train and test/ work best on test data ❌(bad: no idea how algorithm will perform on new data- may just pick the right set of hyperparameters that cause our algorithm to work well on this training data)
-idea3: split data into train, valuation and test/ choose hyperparameters on val and evaluate on test
-idea3: cross-validation, used for small datasets not deep learning(computation expensive)/ try each fold as validation and average the result
what is the difference between validation set and test set?
our algorithm memorizes all the training set, now we will take each of elment of the validation set compared with training data and then use this to determine what is the accuracy of classifer
representative: partition should be random for train data and test data
K-nearest neighbor on images never used
-very slow at test time
-distance metrics on pixels are not informative
-curse of dimensionability/ you never get enough images to cover each pixels in high dimensional space
(ex. dimensions=1, points=4; dimensions=2, points=16)
Linear Classification
parametric approach: we only need parameters at test time, allow our models to be more efficient and can actually run on small devices
-problem: only learn one template for each class