1 / 71

Business 260: Managerial Decision Analysis Professor David Mease Lecture 7 Agenda:

Business 260: Managerial Decision Analysis Professor David Mease Lecture 7 Agenda: 1) Reminder about Homework #3 (due Thursday 4/23) 2) Discuss Exam 3 (Thursday 4/23) 3) Finish Data Mining Book Chapter 4 4) Data Mining Book Chapter 5. Homework #3 Homework #3 will be due Thursday 4/23

Télécharger la présentation

Business 260: Managerial Decision Analysis Professor David Mease Lecture 7 Agenda:

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Business 260: Managerial Decision Analysis Professor David Mease Lecture 7 Agenda: 1) Reminder about Homework #3 (due Thursday 4/23) 2) Discuss Exam 3 (Thursday 4/23) 3) Finish Data Mining Book Chapter 4 4) Data Mining Book Chapter 5

  2. Homework #3 Homework #3 will be due Thursday 4/23 We will have our last exam that day after we review the solutions The homework is posted on the class web page: http://www.cob.sjsu.edu/mease_d/bus260/260homework.html The solutions are posted so you can check your answers: http://www.cob.sjsu.edu/mease_d/bus260/260homework_solutions.html

  3. Exam #3 We will have the 3rd exam covering Lectures 6 and 7 and the assigned data mining readings Thursday 4/23 after we go over the homework It is worth 30 total points (30% of your grade) There are 6 multiple choice questions (18% total) and 6 non-multiple choice questions (82% total) It is closed notes and closed book but you will have this: http://www.cob.sjsu.edu/mease_d/bus260/260formula_sheets.html You will have 2 hours to complete the exam Remember to bring a pocket calculator Some example questions are on the next 10 slides

  4. Exam 3 Example Question #1: What is the definition of data mining used in your textbook? A) the process of automatically discovering useful information in large data repositories B) the computer-assisted process of digging through and analyzing enormous sets of data and then extracting the meaning of the data C) an analytic process designed to explore data in search of consistent patterns and/or systematic relationships between variables, and then to validate the findings by applying the detected patterns to new subsets of data

  5. Exam 3 Example Question #2: If my data frame in R is called “data”, which of the following will give me the third column? A) data[2,] B) data[3,] C) data[,2] D) data[,3] E) data(2,) F) data(3,) G) data(,2) H) data(,3)

  6. Exam 3 Example Question #3: What is the R command to change the default directory which we used in class? A) chdir() B) ls() C) ls-a() D) cd() E) cd-a() F) setwd() G) go()

  7. Exam 3 Example Question #4: Homework 3 question #2

  8. Exam 3 Example Question #5: Homework 3 question #3

  9. Exam 3 Example Question #6: Homework 3 question #4

  10. Exam 3 Example Question #7: Chapters 5 textbook problem #17 part a:

  11. Exam 3 Example Question #8: Compute the precision, recall, F-measure and misclassification error rate with respect to the positive class when a cutoff of P=.50 is used for model M2.

  12. Exam 3 Example Question #9: Which of the following describes bagging as discussed in class? A) Bagging combines simple base classifiers by upweighting data points which are classified incorrectly B) Bagging builds different classifiers by training on repeated samples (with replacement) from the data C) Bagging usually gives zero training error, but rarely overfits which is very curious D) All of these

  13. Exam 3 Example Question #10: For the one dimensional data at the right, give the k-nearest neighbor classifier for the points x=2, x=10 and x=120 with k=5.

  14. Introduction to Data Mining by Tan, Steinbach, Kumar Chapter 4: Classification: Basic Concepts, Decision Trees, and Model Evaluation (Chapter 4 is posted at http://www.cob.sjsu.edu/mease_d/bus260/chapter4.pdf)

  15. How to Apply Hunt’s Algorithm • Usually it is done in a “greedy” fashion. • “Greedy” means that the optimal split is chosen at each stage according to some criterion. • This may not be optimal at the end even for the same criterion. • However, the greedy approach is computational efficient so it is popular.

  16. How to Apply Hunt’s Algorithm (continued) • Using the greedy approach we still have to decide 3 things: #1) What attribute test conditions to consider #2) What criterion to use to select the “best” split #3) When to stop splitting • For #1 we will consider only binary splits for both numeric and categorical predictors as discussed on the next slide • For #2 we will consider misclassification error, Gini index and entropy • #3 is a subtle business involving model selection. It is tricky because we don’t want to overfit or underfit.

  17. #3) When to stop splitting • This is a subtle business involving model selection. It is tricky because we don’t want to overfit or underfit. • One idea would be to monitor misclassification error (or the Gini index or entropy) on the test data set and stop when this begins to increase. • “Pruning” is a more popular technique.

  18. Pruning • “Pruning” is a popular technique for choosing the right tree size • Your book calls it post-pruning (page 185) to differentiate it from prepruning • With (post-) pruning, a large tree is first grown top-down by one criterion and then trimmed back in a bottom up approach according to a second criterion • Rpart() uses (post-) pruning since it basically follows the CART algorithm (Breiman, Friedman, Olshen, and Stone, 1984, Classification and Regression Trees)

  19. Introduction to Data Mining by Tan, Steinbach, Kumar Chapter 5: Classification: Alternative Techniques (The sections we will cover in Chapter 5 are posted at http://www.cob.sjsu.edu/mease_d/bus260/chapter5.pdf)

  20. The Class Imbalance Problem (Sec. 5.7, p. 204) • So far we have treated the two classes equally. We have assumed the same loss for both types of misclassification, used 50% as the cutoff and always assigned the label of the majority class. • This is appropriate if the following three conditions are met 1) We suffer the same cost for both types of errors 2) We are interested in the probability of 0.5 only 3) The ratio of the two classes in our training data will match that in the population to which we will apply the model

  21. The Class Imbalance Problem (Sec. 5.7, p. 204) • If any one of these three conditions is not true, it may be desirable to “turn up” or “turn down” the number of observations being classified as the positive class. • This can be done in a number of ways depending on the classifier. • Methods for doing this include choosing a probability different from 0.5, using a threshold on some continuous confidence output or under/over-sampling.

  22. Recall and Precision (page 297) • When dealing with class imbalance it is often useful to look at recall and precision separately • Recall = • Precision = • Before we just used accuracy =

  23. The F Measure (page 297) • F combines recall and precision into one number • F = • It equals the harmonic mean of recall and precision • Your book calls it the F1 measure because it weights both recall and precision equally • See http://en.wikipedia.org/wiki/Information_retrieval

  24. The ROC Curve (Sec 5.7.2, p. 298) • ROC stands for Receiver Operating Characteristic • Since we can “turn up” or “turn down” the number of observations being classified as the positive class, we can have many different values of true positive rate (TPR) and false positive rate (FPR) for the same classifier. TPR= FPR= • The ROC curve plots TPR on the y-axis and FPR on the x-axis

  25. The ROC Curve (Sec 5.7.2, p. 298) • The ROC curve plots TPR on the y-axis and FPR on the x-axis • The diagonal represents random guessing • A good classifier lies near the upper left • ROC curves are useful for comparing 2 classifiers • The better classifier will lie on top more often • The Area Under the Curve (AUC) is often used a metric

  26. In class exercise #92: This is textbook question #17 part (a) on page 322. It is part of your homework so we will not do all of it in class. We will just do the curve for M1.

  27. In class exercise #93: This is textbook question #17 part (b) on page 322.

  28. Additional Classification Techniques • Decision trees are just one method for classification • We will learn additional methods in this chapter: - Nearest Neighbor - Support Vector Machines - Bagging - Random Forests - Boosting

  29. Nearest Neighbor (Section 5.2, page 223) • You can use nearest neighbor classifiers if you have some way of defining “distances” between attributes • The k-nearest neighbor classifier classifies a point based on the majority of the k closest training points

  30. Nearest Neighbor (Section 5.2, page 223) • Here is a plot I made using R showing the 1-nearest neighbor classifier on a 2-dimensional data set.

  31. Nearest Neighbor (Section 5.2, page 223) • Nearest neighbor methods work very poorly when the dimensionality is large (meaning there are a large number of attributes) • The scales of the different attributes are important. If a single numeric attribute has a large spread, it can dominate the distance metric. A common practice is to scale all numeric attributes to have equal variance. • The knn() function in R in the library “class” does a k-nearest neighbor classification using Euclidean distance.

  32. In class exercise #94: Use knn() in R to fit the 1-nearest-neighbor classifier to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv

  33. In class exercise #94: Use knn() in R to fit the 1-nearest-neighbor classifier to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv Solution: install.packages("class") library(class) train<-read.csv("sonar_train.csv",header=FALSE) y<-as.factor(train[,61]) x<-train[,1:60] fit<-knn(x,x,y,k=1) 1-sum(y==fit)/length(y)

  34. In class exercise #94: Use knn() in R to fit the 1-nearest-neighbor classifier to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Use all the default values. Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv Solution (continued): test<-read.csv("sonar_test.csv",header=FALSE) y_test<-as.factor(test[,61]) x_test<-test[,1:60] fit_test<-knn(x,x_test,y,k=1) 1-sum(y_test==fit_test)/length(y_test)

  35. Support Vector Machines (Section 5.5, page 256) • If the two classes can be separated perfectly by a line in the x space, how do we choose the “best” line?

  36. Support Vector Machines (Section 5.5, page 256) • If the two classes can be separated perfectly by a line in the x space, how do we choose the “best” line?

  37. Support Vector Machines (Section 5.5, page 256) • If the two classes can be separated perfectly by a line in the x space, how do we choose the “best” line?

  38. Support Vector Machines (Section 5.5, page 256) • If the two classes can be separated perfectly by a line in the x space, how do we choose the “best” line?

  39. Support Vector Machines (Section 5.5, page 256) • If the two classes can be separated perfectly by a line in the x space, how do we choose the “best” line?

  40. Support Vector Machines (Section 5.5, page 256) • One solution is to choose the line (hyperplane) with the largest margin. The margin is the distance between the two parallel lines on either side. B 1 B 2 b 21 b 22 margin b 11 b 12

  41. Support Vector Machines (Section 5.5, page 256) • Here is the notation your book uses:

  42. Support Vector Machines (Section 5.5, page 256) • This can be formulated as a constrained optimization problem. • We want to maximize • This is equivalent to minimizing • We have the following constraints • So we have a quadratic objective function with linear constraints which means it is a convex optimization problem and we can use Lagrange multipliers

  43. Support Vector Machines (Section 5.5, page 256) • What if the problem is not linearly separable? • Then we can introduce slack variables: Minimize Subject to

  44. Support Vector Machines (Section 5.5, page 256) • What if the boundary is not linear? • Then we can use transformations of the variables to map into a higher dimensional space

  45. Support Vector Machines in R • The function svm in the package e1071 can fit support vector machines in R • Note that the default kernel is not linear – use kernel=“linear” to get a linear kernel

  46. In class exercise #95: Use svm() in R to fit the default svm to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv

  47. In class exercise #95: Use svm() in R to fit the default svm to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv Solution: install.packages("e1071") library(e1071) train<-read.csv("sonar_train.csv",header=FALSE) y<-as.factor(train[,61]) x<-train[,1:60] fit<-svm(x,y) 1-sum(y==predict(fit,x))/length(y)

  48. In class exercise #95: Use svm() in R to fit the default svm to the last column of the sonar training data at http://www-stat.wharton.upenn.edu/~dmease/sonar_train.csv Compute the misclassification error on the training data and also on the test data at http://www-stat.wharton.upenn.edu/~dmease/sonar_test.csv Solution (continued): test<-read.csv("sonar_test.csv",header=FALSE) y_test<-as.factor(test[,61]) x_test<-test[,1:60] 1-sum(y_test==predict(fit,x_test))/length(y_test)

  49. In class exercise #96: Use svm() in R with kernel=“linear” and cost=100000 to fit the toy 2-dimensional data below. Provide a plot of the resulting classification rule. x2 y x1

  50. In class exercise #96: Use svm() in R with kernel=“linear” and cost=100000 to fit the toy 2-dimensional data below. Provide a plot of the resulting classification rule. Solution: x<-matrix(c(0,.1,.8,.9,.4,.5, .3,.7,.1,.4,.7,.3,.5,.2,.8,.6,.8,0,.8,.3), ncol=2,byrow=T) y<-as.factor(c(rep(-1,5),rep(1,5))) plot(x,pch=19,xlim=c(0,1),ylim=c(0,1), col=2*as.numeric(y),cex=2, xlab=expression(x[1]),ylab=expression(x[2])) x2 y x1

More Related