27
ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς Κατηγοριοποίηση 3 ο Φροντιστήριο Σκούρα Αγγελική [email protected]

ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Ε Ξ Ό Ρ Υ Ξ Η Δ Ε Δ Ο Μ Έ Ν Ω Ν Κ Α Ι Α Λ Γ Ό Ρ Ι Θ Μ Ο Ι Μ Ά Θ Η Σ Η ς

Κατηγοριοποίηση

3ο Φροντιστήριο

Σκούρα Αγγελική

[email protected]

Page 2: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Κατηγοριοποίηση (Classification)

Σκοπός:

Learn a method for predicting the instance class from

pre-labeled (classified) instances

Συνήθεις Τεχνικές:

1) Δέντρα Αποφάσεων (Decision Trees)

2) Νευρωνικά Δίκτυα (Neural Networks)

3) K-πλησιέστερων γειτόνων (k-Nearest Neighbors, k-NN)

4) Μηχανές Υποστήριξης Διανυσμάτων (Support Vector Machines, SVMs)

5) Bayesian μέθοδοι

Στηρίζεται στην ιδέα της «εκπαίδευσης» με τη βοήθεια ενός υποσυνόλου δεδομένων (σύνολο εκπαίδευσης)

Page 3: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Classification process

Classifier Training

Training data Model

Testing data Model Predicted

scores/labels

Training Phase

Testing Phase

Classifier parameters

Page 4: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

1) Δένδρα Απόφασης

Page 5: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

1) Δένδρα Απόφασης

Page 6: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

2) Νευρωνικά Δίκτυα

Page 7: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

2) Νευρωνικά Δίκτυα

• Οι νευρώνες είναι το δομικό στοιχείο του δικτύου. Υπάρχουν δύο είδη νευρώνων, οι νευρώνες εισόδου και οι υπολογιστικοί νευρώνες. – Οι νευρώνες εισόδου δεν υπολογίζουν

τίποτα, μεσολαβούν ανάμεσα στις εισόδους του δικτύου και τους υπολογιστικούς νευρώνες.

– Οι υπολογιστικοί νευρώνες πολλαπλασιάζουν τις εισόδους τους με τα συναπτικά βάρη και υπολογίζουν το άθροισμα του γινομένου. Το άθροισμα που προκύπτει είναι το όρισμα της συνάρτησης μεταφοράς.

• Συνάρτηση μεταφοράς, η οποία μπορεί να είναι:

– βηματική (step), – γραμμική (linear), – μη γραμμική (non-linear), – στοχαστική (stochastic).

Page 8: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

3) k-πλησιέστεροι γείτονες

The k-NN Rule:

If the number of pre-classified points is large it makes good sense to use, instead of the single nearest neighbor, the majority vote of the nearest k neighbors. This method is referred to as the k-NN rule.

The number k should be:

large to minimize the probability of misclassifying x

small (with respect to the number of samples) so that the points are close enough to x to give an accurate estimate of the true class of x

Παραλλαγές:

Weighted K-nn

Page 9: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

4) Μηχανές Διανυσμάτων Υποστήριξης

Οι Μηχανές Υποστήριξης Διανυσμάτων

είναι μια μέθοδος μηχανικής μάθησης για δυαδικά προβλήματα κατηγοριοποίησης

Προβάλλουν τα σημεία του συνόλου εκπαίδευσης σε έναν χώρο περισσοτέρων διαστάσεων και βρίσκουν το υπερεπίπεδο το οποίο διαχωρίζει βέλτιστα τα σημεία των δύο τάξεων

Τα άγνωστα σημεία ταξινομούνται σύμφωνα με την πλευρά του υπερεπίπεδου στην οποία βρίσκονται

Τα διανύσματα τα οποία ορίζουν το υπερεπίπεδο που χωρίζει τις δύο τάξεις ονομάζονται διανύσματα υποστήριξης (support vectors)

Page 10: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

5) Bayesian Μέθοδοι

Βασίζεται στη πιθανοτική θεωρία κατηγοριοποίησης του κανόνα του Bayes

Στόχος είναι να κατηγοριοποιηθεί ένα δείγμα Χ σε μια από τις δεδομένες κατηγορίες C1,C2,..,Cn χρησιμοποιώντας ένα μοντέλο πιθανότητας που ορίζεται σύμφωνα με τη θεωρία του Bayes

Πρόκειται για κατηγοριοποιητές που κάνουν αποτίμηση πιθανοτήτων και όχι πρόβλεψη Αυτό πολλές φορές είναι πιο χρήσιμο και αποτελεσματικό

Εδώ οι προβλέψεις έχουν έναν βαθμό και σκοπός είναι το αναμενόμενο κόστος να ελαχιστοποιείται

Page 11: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation which method works best for classification

No classification model is uniformly the best

Comparison by means of

Accuracy, precision, sensitivity, specificity, …

Speed of training

Speed of model application

Noise tolerance

Explanation ability

Many times: hybrid, integrated models

Page 12: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Μετρικές Αξιολόγησης Μεθόδων Κατηγοριοποίησης

Χρόνος Εκπαίδευσης

Χρόνος Εκτέλεσης

Ανοχή στο Θόρυβο

Χρήση Προϋπάρχουσας Γνώσης

Ακρίβεια Κατανοησιμ

ότητα

Δέντρα Απόφασης Μικρός Μικρός Μικρή Όχι Μέτρια Καλή

Νευρωνικά Δίκτυα

Μεγάλος Μικρός

Καλή Όχι Καλή Μικρή

Bayesian Μέθοδοι

Μεγάλος

Μικρός

Καλή Ναι Καλή Καλή

“Αδρή” Σύγκριση Βασικών Μεθόδων Κατηγοριοποίησης

Page 13: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation: Is my model good?

Evaluation metrics: accuracy, precision-recall, Area Under ROC Curve (AUC)…

Evaluation options:

Train-Test Split

Use train

Use test

Random split

Cross Validation

3/5/10 folds

Leave-one-out

13

Page 14: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation metrics

Sensitivity or True Positive Rate (TPR) eqv. with hit rate, recall

TPR = TP / P = TP / (TP + FN)

False Positive Rate (FPR) eqv. with fall out

FPR = FP / N = FP / (FP + TN)

Accuracy ACC = (TP + TN) / (P + N)

Positive Predictive Value (PPV) eqv. with precision

PPV = TP / (TP + FP)

actual value

p n total

prediction outcome

p' True

Positive False

Positive P'

n' False

Negative

True Negativ

e N'

total P N

Page 15: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation metrics: F - score

The F score can be interpreted as a weighted average of the precision and recall

F score reaches its best value at 1 and worst score at 0

The traditional F-measure or balanced F-score (F score) is the harmonic mean of precision and recall:

recallprecision

recallprecisionscoreF

)(2_

Page 16: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Παράδειγμα υπολογισμού μετρικών ακρίβειας

Έχοντας ως δεδομένα τα ακόλουθα αποτελέσματα ενός αλγορίθμου κατηγοριοποίησης, υπολογίστε τις μετρικές TPrate

FPrate

Precision

Recall

F-measure

=== Confusion Matrix ===

a b c d e f g <-- classified as 41 0 0 0 0 0 0 | a

0 20 0 0 0 0 0 | b

0 0 3 1 0 1 0 | c

0 0 0 13 0 0 0 | d

0 0 1 0 3 0 0 | e

0 0 0 0 0 5 3 | f 0 0 0 0 0 2 8 | g

Page 17: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Διαφορά μεταξύ Precision και Accuracy

Accuracy is how close a measurement comes to the truth

Precision is how close a measurement comes to another measurement Low precision implies uncertainty

Page 18: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

ROC καμπύλη

In signal detection theory, a receiver operating characteristic (ROC) or simply ROC curve, is a graphical plot of true positive rate vs. false positive rate for a binary classifier system as its discrimination threshold is varied

Ο κατακόρυφος άξονας: Tprate = Sensitivity

Ο οριζόντιος άξονας: Fprate = 1- Specificity

Accuracy is measured by the area under the ROC curve an area of 1 represents a perfect test an area of .5 represents a worthless

test

Page 19: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Παράδειγμα κατασκευής ROC καμπύλης

Ερώτημα

Υποθέτουμε ότι υπάρχουν 2 κλάσεις για τα δεδομένα

diseased (“positive”, P) and healthy (“negative”, N).

Δεδομένα

20 παρατηρήσεις εκ των οποίων 10 είναι Ν και 10 είναι P

οι 10 Ν παρατηρήσεις έχουν τιμές N = {0.3,0.4,0.5,0.5,0.5,0.6,0.7,0.7,0.8,0.9};

οι 10 P παρατηρήσεις έχουν τιμές P = {0.5,0.6,0.6,0.8,0.9,0.9,0.9,1.0,1.2,1.4}

Έστω ο αλγόριθμος κατηγοριοποίησης

For a given value of the threshold, t, the classification rule predicts that an observation belongs to P if it is greater than t

Να κατασκευαστεί η ROC καμπύλη

Λύση

To construct the ROC curve, they first set the threshold, t, to be a large value.

Consider progressively lowering the value of t.

For any value greater than or equal to 1.4, all 20 observations are allocated to group N, so no P individuals are allocated to P (hence tp = 0.0) and all the N individuals are allocated to N (hence fp = 0.0).

Μoving t down to 1.2, one individual (the last) in group P is now allocated to N (hence tp = 0.1) while all the N individuals are still allocated to N (hence fp = 0.0 again).

Continuing in this fashion generates the ROC curve.

Page 20: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation options

Page 21: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Evaluation options

Page 22: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Επιπλέον σημεία που απαιτούν προσοχή κατά την κατηγοριοποίηση

Υπερταύτιση (Overfitting)

Unbalanced datasets

Page 23: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Overfitting

Η «υπερταύτιση» αποτελεί ένα σύνηθες πρόβλημα κατά την κατασκευή κατηγοριοποιητών

Overfitting/Overtraining in supervised learning (e.g. neural network). Training error is shown in blue, validation error in red. If the validation error increases while the training error steadily decreases then a situation of overfitting may have occurred.

Page 24: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Unbalanced datasets

Page 25: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Making most of the data

Page 26: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Not only Weka…Many classification tools

Kernel SVM: libsvm, svmlight

Linear SVM/LogReg: liblinear

LogReg: BBK

Naïve Bayes, Decision Trees: Weka

Bagging, Boosting on trees: FEST

rpart package, Orange, Waffle, Shogun, Sgd, etc.

26

Page 27: ΕΞΌΡΥΞΗ ΔΕΔΟΜΈΝΩΝ ΚΑΙ ΑΛΓΌΡΙΘΜΟΙ ΜΆΘΗΣΗς · Evaluation metrics: F - score The F score can be interpreted as a weighted average of the precision

Ευχαριστώ για την προσοχή σας…