Download Entropy and Information Gain and more Exams Art in PDF only on Docsity!
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 54
Entropy and Information Gain
The entropy (very common in
Information Theory) characterizes the
(im)purity of an arbitrary collection of
examples
Information Gain is the expected
reduction in entropy caused by
partitioning the examples according to a
given attribute
Entropy Calculations
If we have a set with k different values in it, we can calculate
the entropy as follows:
Where P(valuei) is the probability of getting the ith^ value when
randomly selecting one from the set.
So, for the set R = {a,a,a,b,b,b,b,b}
k
entropy ( Set ) I ( Set ) i 1 P ( valuei ) log 2 P ( valuei )
entropy ( R )= I ( R )= −^ 83 log 2 83 + 85 log 2 85
a-values b-values
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 56
Looking at some data
YellowYellow LargeSmall IrregularIrregular ++
YellowYellow LargeLarge RoundRound --
YellowYellow LargeLarge RoundRound -+
YellowGreen LargeSmall RoundRound --
YellowYellow SmallSmall RoundRound ++
YellowYellow SmallLarge RoundRound ++
GreenGreen LargeSmall IrregularIrregular -+
YellowYellow SmallSmall RoundRound -+
Color Size Shape Edible?
Entropy for our data set
16 instances: 9 positive, 7 negative.
This equals: 0.
This makes sense – it’s almost a 50/50 split; so,
the entropy should be close to 1.
^ +
log^7
log^9
I ( all _ data )^922
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 60
G(attrib) = I(parent) – I(attrib)
G(size) = I(S) – I(SSize)
G(size) = 0.9836 – 0.
G(size) = 0.
Entropy of all data at parent node = I(parent) = 0.
Child’s expected entropy for ‘size’ split = I(size) = 0.
So, we have gained 0.1008 bits of information about the dataset by
choosing ‘size’ as the first branch of our decision tree.
We want to calculate the information gain (or entropy reduction).
This is the reduction in ‘uncertainty’ when choosing our first branch
as ‘size’. We will represent information gain as “G.”
Example-based Classifiers
Example-based classifiers (EBCs) learns
from the categories of the training
documents similar to the one to be
classified
The most frequently used EBC is the k-NN
algorithm
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 62
k Nearest Neighbor Classification
1. To classify document d into class c
2. Define k-neighborhood N as k nearest neighbors (according
to a given distance or similarity measure) of d
3. Count number of documents kc in N that belong to c
4. Estimate P(c| d) as kc/k
5. Choose as class argmaxc P(c| d) [ = majority class]
Example: k=6 (6NN)
Government
Science
Arts
P(science| )?
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 66
K Nearest-Neighbor
Using only the closest example to determine
the categorization is subject to errors due to:
A single atypical example.
Noise (i.e. error) in the category label of a single
training example.
More robust alternative is to find the k most-
similar examples and return the majority
category of these k examples.
Value of k is typically odd to avoid ties;
kNN decision boundaries
Government
Science
Arts
Boundariesare in
principlearbitrary
surfaces –but usually
polyhedra
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 68
Similarity Metrics
Nearest neighbor method depends on a
similarity (or distance) metric.
Simplest for continuous m-dimensional instance
space is Euclidian distance.
Simplest for m-dimensional binary instance
space is Hamming distance (number of feature
values that differ).
For text, cosine similarity of tf.idf weighted
vectors is typically most effective.
.. But any metric can be used!!
Nearest Neighbor with Inverted
Index
Naively finding nearest neighbors requires a linear
search through | D| documents in collection
But determining k nearest neighbors is the same as
determining the k best retrievals using the test
document as a query to a database of training
documents.
Use standard vector space inverted index methods to
find the k nearest neighbors.
Testing Timenumber of training documents in which a test-document word: O( B|Vt|) where B is the average
appears.
Typically B << | D|
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 72
Rocchio: a simple case study
When δ=
For each category (possibly, more than one),
compute a prototype vector by summing the
vectors of the training documents in the
category.
Prototype = centroid of members of class
Assign test documents to the category with
the closest prototype vector based on cosine
similarity.
Rocchio Time Complexity
Note: The time to add two sparse vectors is
proportional to minimum number of non-zero entries in
the two vectors.
Training Timethe average length of a document in: O(| D|( Ld + | Vd|)) = O(| D and D V| Ld) where Ld is
vocabulary size for a document in D. d^ is the average
Test Time where L : O( Lt + |C||Vt|)
the average vocabulary size for a test document.t^ is the average length of a test document and |^ Vt^ |^ is
Assumes lengths ofduring training, allowing cosSim( centroid vectors are computed and storedd, c
proportional to the number of non-zero entries in^ i) to be computed in time d (i.e. |Vt|)
Dip. di MatematicaPura ed Applicata F. Aiolli - Sistemi Informativi2007/2008 74
The Rocchio Method (Pro and Cons)
Advantages The method is efficient and easy to implement The resulting classifiers are easy interpretable. This doesnot happen for other approaches such as e.g. NNs
Drawbacks The resulting classifier are seldom very effective[Cohen&Singer96, Joachims98,Lewis+96,Yang99] If the documents in cclassifier may be very ineffective: as all linear classifers, itj occur in disjoint clusters a Rocchio partition the space of documents in two linearly separable subspaces. But many naturally occurring categories are notlinearly separable
Rocchio Vs k-NN