data

Enron e-mails. Used in investigation where Enron is accused of distorting prices in the California electricity market.

This data comes from the 2010 TREC Legal Track.

emails <- read.csv("energy_bids.csv", stringsAsFactors = FALSE)
str(emails)
## 'data.frame':    855 obs. of  2 variables:
##  $ email     : chr  "North America's integrated electricity market requires cooperation on environmental policies Commission for Env"| __truncated__ "FYI -----Original Message----- From: \t\"Ginny Feliciano\" <gfeliciano@earthlink.net>@ENRON [mailto:IMCEANOTES-"| __truncated__ "14:13:53 Synchronizing Mailbox 'Kean, Steven J.' 14:13:53 Synchronizing Hierarchy 14:13:53 Synchronizing Favori"| __truncated__ "^ ----- Forwarded by Steven J Kean/NA/Enron on 03/02/2001 12:27 PM ----- Suzanne_Nimocks@mckinsey.com Sent by: "| __truncated__ ...
##  $ responsive: int  0 1 0 1 0 0 1 0 0 0 ...

‘responsive’ e-mails are thought relevant for subsequent use in legal proceedings against Enron.

a typical e-mail

emails$email[[1]]
## [1] "North America's integrated electricity market requires cooperation on environmental policies Commission for Environmental Cooperation releases working paper on North America's electricity market Montreal, 27 November 2001 -- The North American Commission for Environmental Cooperation (CEC) is releasing a working paper highlighting the trend towards increasing trade, competition and cross-border investment in electricity between Canada, Mexico and the United States. It is hoped that the working paper, Environmental Challenges and Opportunities in the Evolving North American Electricity Market, will stimulate public discussion around a CEC symposium of the same title about the need to coordinate environmental policies trinationally as a North America-wide electricity market develops. The CEC symposium will take place in San Diego on 29-30 November, and will bring together leading experts from industry, academia, NGOs and the governments of Canada, Mexico and the United States to consider the impact of the evolving continental electricity market on human health and the environment. \"Our goal [with the working paper and the symposium] is to highlight key environmental issues that must be addressed as the electricity markets in North America become more and more integrated,\" said Janine Ferretti, executive director of the CEC. \"We want to stimulate discussion around the important policy questions being raised so that countries can cooperate in their approach to energy and the environment.\" The CEC, an international organization created under an environmental side agreement to NAFTA known as the North American Agreement on Environmental Cooperation, was established to address regional environmental concerns, help prevent potential trade and environmental conflicts, and promote the effective enforcement of environmental law. The CEC Secretariat believes that greater North American cooperation on environmental policies regarding the continental electricity market is necessary to: *  protect air quality and mitigate climate change, *  minimize the possibility of environment-based trade disputes, *  ensure a dependable supply of reasonably priced electricity across North America *  avoid creation of pollution havens, and *  ensure local and national environmental measures remain effective. The Changing Market The working paper profiles the rapid changing North American electricity market. For example, in 2001, the US is projected to export 13.1 thousand gigawatt-hours (GWh) of electricity to Canada and Mexico. By 2007, this number is projected to grow to 16.9 thousand GWh of electricity. \"Over the past few decades, the North American electricity market has developed into a complex array of cross-border transactions and relationships,\" said Phil Sharp, former US congressman and chairman of the CEC's Electricity Advisory Board. \"We need to achieve this new level of cooperation in our environmental approaches as well.\" The Environmental Profile of the Electricity Sector The electricity sector is the single largest source of nationally reported toxins in the United States and Canada and a large source in Mexico. In the US, the electricity sector emits approximately 25 percent of all NOx emissions, roughly 35 percent of all CO2 emissions, 25 percent of all mercury emissions and almost 70 percent of SO2 emissions. These emissions have a large impact on airsheds, watersheds and migratory species corridors that are often shared between the three North American countries. \"We want to discuss the possible outcomes from greater efforts to coordinate federal, state or provincial environmental laws and policies that relate to the electricity sector,\" said Ferretti. \"How can we develop more compatible environmental approaches to help make domestic environmental policies more effective?\" The Effects of an Integrated Electricity Market One key issue raised in the paper is the effect of market integration on the competitiveness of particular fuels such as coal, natural gas or renewables. Fuel choice largely determines environmental impacts from a specific facility, along with pollution control technologies, performance standards and regulations. The paper highlights other impacts of a highly competitive market as well. For example, concerns about so called \"pollution havens\" arise when significant differences in environmental laws or enforcement practices induce power companies to locate their operations in jurisdictions with lower standards. \"The CEC Secretariat is exploring what additional environmental policies will work in this restructured market and how these policies can be adapted to ensure that they enhance competitiveness and benefit the entire region,\" said Sharp. Because trade rules and policy measures directly influence the variables that drive a successfully integrated North American electricity market, the working paper also addresses fuel choice, technology, pollution control strategies and subsidies. The CEC will use the information gathered during the discussion period to develop a final report that will be submitted to the Council in early 2002. For more information or to view the live video webcast of the symposium, please go to: http://www.cec.org/electricity. You may download the working paper and other supporting documents from: http://www.cec.org/programs_projects/other_initiatives/electricity/docs.cfm?varlan=english. Commission for Environmental Cooperation 393, rue St-Jacques Ouest, Bureau 200 Montréal (Québec) Canada H2Y 1N9 Tel: (514) 350-4300; Fax: (514) 350-4314 E-mail: info@ccemtl.org ***********"
cat("\nResponsive : ", emails$responsive[[1]])
## 
## Responsive :  0

responsive e-mails

table(emails$responsive)
## 
##   0   1 
## 716 139

pre-process e-mails for ease of analysis

corpus <- VCorpus(VectorSource(emails$email))

corpus = tm_map(corpus, content_transformer(tolower)) # lower-case
corpus = tm_map(corpus, removePunctuation)            # remove punctuation
corpus = tm_map(corpus, removeWords, stopwords("english")) # remove stop words
corpus = tm_map(corpus, stemDocument)                 # reduce words to 'stems'

bag of words

dtm <- DocumentTermMatrix(corpus)
dtm
## <<DocumentTermMatrix (documents: 855, terms: 22141)>>
## Non-/sparse entries: 102834/18827721
## Sparsity           : 99%
## Maximal term length: 113
## Weighting          : term frequency (tf)

too many terms (22141)!

dtm <- removeSparseTerms(dtm, 0.97)
# only keep words present in at least 3% of documents
dtm
## <<DocumentTermMatrix (documents: 855, terms: 788)>>
## Non-/sparse entries: 51612/622128
## Sparsity           : 92%
## Maximal term length: 19
## Weighting          : term frequency (tf)

Now just 788 terms.

labeledterms <- as.data.frame(as.matrix(dtm))
labeledterms$responsive <- emails$responsive # our outcome variable
str(labeledterms)
## 'data.frame':    855 obs. of  789 variables:
##  $ 100                : num  0 0 0 0 0 0 5 0 0 0 ...
##  $ 1400               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ 1999               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ 2000               : num  0 0 1 0 1 0 6 0 1 0 ...
##  $ 2001               : num  2 1 0 0 0 0 7 0 0 0 ...
##  $ 713                : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ 77002              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ abl                : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ accept             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ access             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ accord             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ account            : num  0 0 0 0 0 0 3 0 0 0 ...
##  $ act                : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ action             : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ activ              : num  0 0 1 0 1 0 1 0 0 0 ...
##  $ actual             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ add                : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ addit              : num  1 0 0 0 0 0 1 0 0 0 ...
##  $ address            : num  3 0 0 0 2 0 0 0 0 1 ...
##  $ administr          : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ advanc             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ advis              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ affect             : num  0 0 0 0 2 0 0 0 0 0 ...
##  $ afternoon          : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ agenc              : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ ago                : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ agre               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ agreement          : num  2 0 0 0 2 0 1 0 0 1 ...
##  $ alan               : num  0 0 0 0 0 1 0 0 0 0 ...
##  $ allow              : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ along              : num  1 0 0 0 1 0 1 0 0 0 ...
##  $ alreadi            : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ also               : num  1 0 0 0 0 0 8 0 0 0 ...
##  $ altern             : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ although           : num  0 0 0 0 0 0 6 0 0 0 ...
##  $ amend              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ america            : num  4 0 0 0 0 0 0 0 1 0 ...
##  $ among              : num  0 0 0 0 0 0 3 0 0 0 ...
##  $ amount             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ analysi            : num  0 0 0 2 0 0 0 0 0 0 ...
##  $ analyst            : num  0 0 0 0 0 0 6 0 0 0 ...
##  $ andor              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ andrew             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ announc            : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ anoth              : num  0 0 0 0 0 0 6 0 0 0 ...
##  $ answer             : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ anyon              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ anyth              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ appear             : num  0 0 0 0 0 0 3 0 0 0 ...
##  $ appli              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ applic             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ appreci            : num  0 0 0 0 1 0 0 0 0 0 ...
##  $ approach           : num  3 0 0 0 0 0 1 0 0 0 ...
##  $ appropri           : num  0 0 0 0 0 0 0 1 0 0 ...
##  $ approv             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ approxim           : num  1 0 0 0 0 0 1 0 0 0 ...
##  $ april              : num  0 0 0 0 0 0 3 0 0 0 ...
##  $ area               : num  0 0 0 0 1 0 3 0 0 0 ...
##  $ around             : num  2 0 0 0 0 0 1 0 0 0 ...
##  $ arrang             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ articl             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ ask                : num  0 0 0 0 0 1 0 0 0 0 ...
##  $ asset              : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ assist             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ associ             : num  0 0 1 0 1 0 0 0 0 0 ...
##  $ assum              : num  0 0 0 0 0 1 0 0 0 0 ...
##  $ attach             : num  0 1 0 1 1 0 1 0 3 1 ...
##  $ attend             : num  0 0 0 0 0 0 0 0 1 0 ...
##  $ attent             : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ attorney           : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ august             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ author             : num  0 0 1 0 0 0 0 0 0 0 ...
##  $ avail              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ averag             : num  0 0 0 0 0 0 5 0 0 0 ...
##  $ avoid              : num  1 0 0 0 1 0 2 0 0 0 ...
##  $ awar               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ back               : num  0 0 0 0 1 1 1 0 0 0 ...
##  $ balanc             : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ bank               : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ base               : num  0 0 0 0 1 0 9 0 0 0 ...
##  $ basi               : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ becom              : num  1 0 0 0 0 0 4 0 0 0 ...
##  $ begin              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ believ             : num  1 0 0 0 0 0 0 0 0 0 ...
##  $ benefit            : num  1 0 0 0 0 0 5 0 0 0 ...
##  $ best               : num  0 0 0 0 0 0 0 0 0 1 ...
##  $ better             : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ bid                : num  0 0 0 0 0 0 1 0 0 0 ...
##  $ big                : num  0 0 0 0 0 1 6 0 0 0 ...
##  $ bill               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ billion            : num  0 0 0 0 0 0 2 0 0 0 ...
##  $ bit                : num  0 0 0 0 0 1 2 0 0 0 ...
##  $ board              : num  1 0 0 0 0 0 0 0 0 0 ...
##  $ bob                : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ book               : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ brian              : num  0 1 0 0 0 0 0 0 0 0 ...
##  $ brief              : num  0 0 0 0 0 0 0 0 0 0 ...
##  $ bring              : num  1 0 0 0 0 0 2 0 0 0 ...
##  $ build              : num  0 0 0 0 0 0 7 0 1 0 ...
##   [list output truncated]

Create training and test set

set.seed(144)

split <- sample.split(labeledterms$responsive, SplitRatio = 0.7)
train <- subset(labeledterms, split == TRUE)
test <- subset(labeledterms, split == FALSE)

Classication and Regression Trees (CART) models

emailCART <- rpart(responsive ~ .,
                   data = train,
                   method = "class")
prp(emailCART)

Jeff Skillings was the CEO of Enron.

evaluate on test set

predictCART <- predict(emailCART,
                       newdata = test)
predictCART[1:10,]
##            0          1
## 2  0.2156863 0.78431373
## 5  0.9557522 0.04424779
## 11 0.9557522 0.04424779
## 13 0.8125000 0.18750000
## 28 0.4000000 0.60000000
## 37 0.9557522 0.04424779
## 47 0.9557522 0.04424779
## 58 0.9557522 0.04424779
## 61 0.1250000 0.87500000
## 62 0.1250000 0.87500000

Left column is the predicted probability of the document being non-responsive. Right column is the predicted probability of the document being responsive.

predictCART.prob <- predictCART[,2]
tableCART <- table(test$responsive, predictCART.prob > .5)
tableCART
##    
##     FALSE TRUE
##   0   195   20
##   1    17   25
cat("\nAccuracy :", sum(diag(tableCART))/nrow(test))
## 
## Accuracy : 0.8560311
cat("\nAccuracy of baseline model\n(e-mail is not responsive) :", sum(test$responsive == 0)/nrow(test))
## 
## Accuracy of baseline model
## (e-mail is not responsive) : 0.8365759

However, as in most document retrieval applications, there are uneven costs for different types of errors here.

Typically, a human will still have to manually review all of the predicted responsive documents to make sure they are actually responsive.

Therefore, if we have a false positive, in which a non-responsive document is labeled as responsive, the mistake translates to a bit of additional work in the manual review process but no further harm, since the manual review process will remove this erroneous result.

But on the other hand, if we have a false negative, in which a responsive document is labeled as non-responsive by our model, we will miss the document entirely in our predictive coding process.

Therefore, we’re going to assign a higher cost to false negatives than to false positives, which makes this a good time to look at other cut-offs on our ROC curve.

ROC curve

predictROCR <- prediction(predictCART.prob, test$responsive)
perfROCR <- performance(predictROCR, "tpr", "fpr") # true-positive rate vs false-positive rate

plot(perfROCR, colorize=TRUE,
     print.cutoffs.at = seq(0, 0.2, 0.05), text.adj = c(-0.2, 1.7))

cat("\nAUC :", performance(predictROCR, "auc")@y.values[[1]])
## 
## AUC : 0.7936323

Perhaps a threshold of around 0.15?

Using a threshold of 0.15

predictCART.prob <- predictCART[,2]
tableCART <- table(test$responsive, predictCART.prob > .15)
tableCART
##    
##     FALSE TRUE
##   0   176   39
##   1    12   30
cat("\nAccuracy :", sum(diag(tableCART))/nrow(test))
## 
## Accuracy : 0.8015564
cat("\nAccuracy of baseline model\n(e-mail is not responsive) :", sum(test$responsive == 0)/nrow(test))
## 
## Accuracy of baseline model
## (e-mail is not responsive) : 0.8365759