BOOLRULE Procedure
Example 6.3 Using Events in Rule Extraction
This example uses the same input table and the same TEXTMINE procedure call that are used in Example 6.1 to illustrate how you can use events in rule extraction. The DATA step and procedure call are repeated here for convenience.
When TARGETTYPE=MULTICLASS, each level of the target variable defines a category for rule extraction. If you want to extract rules for only a subset of the levels of the target variable, you can use the EVENTS= option to specify the categories for which you want to extract rules.
The following DATA step creates the mylib.reviews data table, which contains nine observations that have four variables. The text variable contains the input reviews. The positive variable contains the sentiment of the reviews: a value of 1 indicates that the review is positive and a value of 0 indicates that the review is negative. The category variable contains the category of the reviews. The did variable contains the ID of the documents. Each row in the data table represents a document for analysis.
data mylib.reviews;
infile datalines delimiter='|' missover;
length text $300 category $20;
input text$ positive category$ did;
datalines;
This is the greatest phone ever! love it!|1|electronics|1
The phone's battery life is too short and screen resolution is low.|0|electronics|2
The screen resolution is low, but I love this tv.|1|electronics|3
The movie itself is great and I like it, although the resolution is low.|1|movies|4
The movie's story is boring and the acting is poor.|0|movies|5
I watched this movie on tv, it's not good on a small screen. |0|movies|6
watched the movie first and loved it, the book is even better!|1|books |7
I like the story in this book, they should put it on screen.|1|books|8
I love the author, but this book is a waste of time, don't buy it.|0|books|9
;
run;
The following TEXTMINE procedure call parses the mylib.reviews data table, stores the term-by-document matrix in the mylib.reviews_bow data table in transactional format, and stores terms that appeared in the mylib.reviews data table in the mylib.reviews_terms data table:
proc textmine data=mylib.reviews;
doc_id
did;
var
text;
parse
nonoungroups
notagging
entities = none
outparent = mylib.reviews_bow
outterms = mylib.reviews_terms
reducef = 1;
run;
The following statements run PROC BOOLRULE to extract rules from the mylib.reviews_bow data table and run PROC PRINT to show the results. TARGETTYPE=BINARY is specified, and category is specified as the target variable, which contains three levels: "electronics," "movies," and "books." Because the "movies" and "books" levels are specified in the EVENTS= option, PROC BOOLRULE procedure extracts rules for "movies" and "books," but not "electronics."
proc boolrule
data = mylib.reviews_bow
docid = _document_
termid = _termnum_
docinfo = mylib.reviews
terminfo = mylib.reviews_terms
minsupports = 1
mpos = 1
gpos = 1;
docinfo
id = did
targettype = binary
targets = (category)
events = ("movies" "books");
terminfo
id = key
label = term;
output
ruleterms = mylib.ruleterms
rules = mylib.rules;
run;
data rules;
set mylib.rules;
proc print data=rules;
var target ruleid rule F1 precision recall;
run;
Output 6.3.1 shows that the mylib.rules data table contains rules that are generated for the "movies" and "books" categories.
Output 6.3.1: The mylib.rules Data Table
| Obs | TARGET | RULEID | RULE | F1 | PRECISION | RECALL |
|---|---|---|---|---|---|---|
| 1 | category | 1 | movie | 0.8 | 1 | 0.66667 |
| 2 | category | 2 | book | 1.0 | 1 | 1.00000 |