Docsity

Algorithms for Classification - Minning Data - Lecture Slides, Slides of Computer Fundamentals

Partial preview of the text

Download Algorithms for Classification - Minning Data - Lecture Slides and more Slides Computer Fundamentals in PDF only on Docsity!

Algorithms for

Classification:

The Basic Methods

Docsity.com

Outline

  • Simplicity first: 1R
  • Naïve Bayes

2 Docsity.com

Simplicity first

  • Simple algorithms often work very well!
  • There are many kinds of simple structure, eg:
    • One attribute does all the work
    • All attributes contribute equally & independently
    • A weighted linear combination might do
    • Instance-based: use a few prototypes
    • Use simple logical rules
  • Success of method depends on the domain

4

Inferring rudimentary rules

  • 1R: learns a 1-level decision tree
    • I.e., rules that all test one particular attribute
  • Basic version
    • One branch for each value
    • Each branch assigns most frequent class
    • Error rate: proportion of instances that don’t belong to the majority
class of their corresponding branch
  • Choose attribute with lowest error rate
( assumes nominal attributes )

5

Evaluating the weather attributes

* indicates a tie

7

Attribute Rules Errors Total errors Outlook Sunny → No 2/5 4/ Overcast → Yes 0/ Rainy → Yes 2/ Temp Hot → No* 2/4 5/ Mild → Yes 2/ Cool → Yes 1/ Humidity High → No 3/7 4/ Normal → Yes 1/ Windy False → Yes 2/8 5/ True → No* 3/

Outlook Temp Humidity Windy Play

Sunny Hot High False No

Sunny Hot High True No

Overcast Hot High False Yes

Rainy Mild High False Yes

Rainy Cool Normal False Yes

Rainy Cool Normal True No

Overcast Cool Normal True Yes

Sunny Mild High False No

Sunny Cool Normal False Yes

Rainy Mild Normal False Yes

Sunny Mild Normal True Yes

Overcast Mild High True Yes

Overcast Hot Normal False Yes

Rainy Mild High True No

Dealing with

numeric attributes

  • Discretize numeric attributes
  • Divide each attribute’s range into intervals
    • Sort instances according to attribute’s values
    • Place breakpoints where the class changes
(the majority class)
  • This minimizes the total error
  • Example: temperature from weather data

8

64 65 68 69 70 71 72 72 75 75 80 81 83 85 Yes | No | Yes Yes Yes | No No Yes | Yes Yes | No | Yes Yes | No

Outlook Temperature Humidity Windy Play Sunny 85 85 False No Sunny 80 90 True No Overcast 83 86 False Yes Rainy 75 80 False Yes … … … … …

Discretization example

  • Example (with min = 3):
  • Final result for temperature attribute

10

64 65 68 69 70 71 72 72 75 75 80 81 83 85 Yes | No | Yes Yes Yes | No No Yes | Yes Yes | No | Yes Yes | No

64 65 68 69 70 71 72 72 75 75 80 81 83 85 Yes No Yes Yes Yes | No No Yes Yes Yes | No Yes Yes No

With overfitting avoidance

  • Resulting rule set:

11

Attribute Rules Errors Total errors Outlook Sunny^ →^ No^ 2/5 4/ Overcast → Yes (^) 0/ Rainy → Yes (^) 2/

Temperature ≤^ 77.5^ →^ Yes^ 3/10 5/ > 77.5 → No* (^) 2/

Humidity ≤^ 82.5^ →^ Yes^ 1/7 3/ > 82.5 and ≤ 95.5 → No (^) 2/ > 95.5 → Yes (^) 0/

Windy False^ →^ Yes^ 2/8 5/ True → No* (^) 3/

Probabilities for weather data

14

Outlook Temperature Humidity Windy Play Yes No Yes No Yes No Yes No Yes No

Sunny 2 3 Hot 2 2 High 3 4 False 6 2 9 5

Overcast 4 0 Mild 4 2 Normal 6 1 True 3 3

Rainy 3 2 Cool 3 1

Sunny 2/9 3/5 Hot 2/9 2/5 High 3/9 4/5 False 6/9 2/5 9/14 5/

Overcast 4/9 0/5 Mild 4/9 2/5 Normal 6/9 1/5 True 3/9 3/

Rainy 3/9 2/5 Cool 3/9 1/5 Outlook^ Temp^ Humidity^ Windy^ Play Sunny Hot High False No Sunny Hot High True No Overcast Hot High False Yes Rainy Mild High False Yes Rainy Cool Normal False Yes Rainy Cool Normal True No Overcast Cool Normal True Yes Sunny Mild High False No Sunny Cool Normal False Yes Rainy Mild Normal False Yes Sunny Mild Normal True Yes Overcast Mild High True Yes Overcast Hot Normal False Yes Rainy Mild High True No

Probabilities for weather data

  • A new day:

15

Outlook Temp. Humidity Windy Play Sunny Cool High True?

Likelihood of the two classes For “yes” = 2/9 × 3/9 × 3/9 × 3/9 × 9/14 = 0. For “no” = 3/5 × 1/5 × 4/5 × 3/5 × 5/14 = 0. Conversion into a probability by normalization: P(“yes”) = 0.0053 / (0.0053 + 0.0206) = 0. P(“no”) = 0.0206 / (0.0053 + 0.0206) = 0.

Outlook Temperature Humidity Windy Play Yes No Yes No Yes No Yes No Yes No

Sunny 2 3 Hot 2 2 High 3 4 False 6 2 9 5

Overcast 4 0 Mild 4 2 Normal 6 1 True 3 3

Rainy 3 2 Cool 3 1

Sunny 2/9 3/5 Hot 2/9 2/5 High 3/9 4/5 False 6/9 2/5 9/14 5/

Overcast 4/9 0/5 Mild 4/9 2/5 Normal 6/9 1/5 True 3/9 3/

Rainy 3/9 2/5 Cool 3/9 1/

Naïve Bayes for classification

  • Classification learning: what’s the probability of the class

given an instance?

  • Evidence E = instance
  • Event H = class value for instance
  • Naïve assumption: evidence splits into parts (i.e. attributes)

that are independent

17

Pr[ ]

Pr[ | ]Pr[ | ] Pr[ | ]Pr[ ] Pr[ | ]

1 1

E

E H E H E H H H E

n

Weather data example

18

Outlook Temp. Humidity Windy Play Sunny Cool High True?

Evidence E

Probability of

class “yes”

Pr[ yes | E ]= Pr[ Outlook = Sunny | yes ]

×Pr[ Temperatur e = Cool | yes ]

×Pr[ Humidity = High | yes ]

×Pr[ Windy = True | yes ]

Pr[ ]

Pr[ ]

E

yes ×

Pr[ ]

E

× × × ×

*Modified probability estimates

  • In some cases adding a constant different from 1 might be

more appropriate

  • Example: attribute outlook for class yes
  • Weights don’t need to be equal

(but they must sum to 1)

20

μ

μ

9

2 / 3

μ

μ

9

4 / 3

μ

μ

9

3 / 3

Sunny Overcast Rainy

μ

μ

9

2 p 1

μ

μ

9

4 p 2

μ

μ

9

3 p 3

Missing values

  • Training: instance is not included in

frequency count for attribute value-class

combination

  • Classification: attribute will be omitted

from calculation

  • Example:

21

Outlook Temp. Humidity Windy Play ? Cool High True?

Likelihood of “yes” = 3/9 × 3/9 × 3/9 × 9/14 = 0.
Likelihood of “no” = 1/5 × 4/5 × 3/5 × 5/14 = 0.
P(“yes”) = 0.0238 / (0.0238 + 0.0343) = 41%
P(“no”) = 0.0343 / (0.0238 + 0.0343) = 59%