business
1
Business Analytics Homework #1 Learning objectives
Use R code for mining and analyzing association rules based on real data files Practice the defining calculation of important values related to association rules
Create your own copy of the transactions file
In BA1_Data.xlsx, in tab rawTransactions in column H from row 2 to the last row of data,
use the RAND() function to generate a random number for each row in the column named
as “Random”. If you are not familiar with this function, read online how to use it. Note that
as soon as you try to do something else in the spreadsheet, these numbers keep changing.
That is OK. The next step will capture one instance of that randomization.
You will take an instance of those random numbers to work with. Copy and paste the values
in column H row 2 to the last row of data to column A row 2 to the last row of data (under
column header “Seq”). It’s important to paste values so they don’t change so use Paste
Special with option “Values”.
Put a filter on columns A through G and sort them by the Seq column in ascending order.
Copy range B2:G801 (first 800 transactions after sorting, without including any info from
columns A and H) to the range A1:F800 in a blank worksheet myTransactions. This means
that you are only going to copy 800 transactions. In fact, those 800 transactions will be
unique to you because of the use of RAND() to order records. Note that you are not copying
the column headers.
Save your Excel file before proceeding.
While you are positioned on the worksheet myTransactions, save your file as a CSV file. You
must be positioned in the worksheet myTransactions or this will not work. To save your file
as a CSV file, you need to go to File‐>Save As, select location, and then go to “Save as type”
and select “CSV (Comma delimited) (*.csv)”. This will save only the active worksheet, which
better be myTransactions. Name this CSV file as XXtransactions where XX are your initials.
For example, were your name George Burdell, you would name the file GBtransactions.
After having saved myTransactions as a CSV, close the CSV file without saving it again. Then
reopen your Excel answerbook. Make sure that the worksheet myTransactions is there. You
2
have to turn in both your version of myTransactions and the rawTransactions worksheet
(which includes the RAND() functions and sorted data).
Read in the transactions and examine the data
Install the R package “arules”, load the package after installation is completed.
Import the transactions from the CSV file you created into a data frame called
XXtransactions where XX are your initials. For example, were your name George Burdell,
you would import transactions into GBtransactions.
Display the summary of the data frame you created through the import.
Take a screenshot and paste the output beginning with >summary into a Word
document. If you’ve done it correctly, your output should look something like Figure 1
except your numbers will be different.
Figure 1 Summary command output
Create an item frequency plot of the top 10 most frequently appearing items.
Copy as text and paste the command you used into the same Word document you have
created.
Take a screenshot and paste the output of the command (from the plots window) into
the same Word document you have been working with. If you’ve done it correctly, your
output should look something like Figure 2 except your numbers will be different.
3
Figure 2 Item frequency plot
Use the apriori algorithm to create association rules
Use the apriori algorithm to create a set of association rules called “XXrules” (again, XX are
your initials like GB for George Burdell). Direct the apriori command to return only rules
having support of at least 0.2 and confidence of at least 0.8.
Copy as text and paste the command you used (not the output) into the Word
document.
Take a screenshot and paste the output beginning with line containing the apriori
command into the Word document. If you’ve done it correctly, your output should look
something like Figure 3 except your screenshot should begin with the command and
your numbers will probably be different.
Figure 3 Apriori command output
Inspect the association rules
Create an R command to inspect the 5 rules with the highest lift.
Take a screenshot and paste the output beginning with the >inspect command into the
Word document. If you’ve done it correctly, your output should look something like 4
4
except your screenshot should begin with the command and your numbers will probably
be different.
Figure 4 Inspect rules output
Verify association‐rule calculations
Pick an association rule that interests you the most from the 5 rules generated in the
previous step. Use the subset() function to count the support of the antecedent and the
consequent of the rule in the transaction data. Use the formula we introduced in class to
verify the calculation of confidence and lift generated by the R package.
In the same Word document you have been working with, write down the association
rule you choose to verify: {Antecedent} ‐> {Consequent}; record the support counts
of {Antecedent}, {Consequent}, {Antecedent & Consequent}; explicitly calculate the
confidence and lift using the defining formula we introduced in class. Be sure to
include the following:
Support count (Antecedent)
Support count (Consequent)
Support count (Antecedent & Consequent)
Confidence = (… formula …) = (… number1 / number2 …) = (… result …)
Lift = (… formula …) = (… number1 / number2 …) = (… result …)
If you did correctly, the calculation results should be consistent with the output by the
R package in the previous step.
Submission:
The assignment is due on Feb 23 (Tuesday) midnight 11:59pm.
Submit the Word file (which includes 4 screenshots, 2 text R commands, and the calculation of association rule values) and the Excel file (which includes rawTransactions and myTransactions tabs) through the “Assignments” page on Canvas. Name both files as LastFirst‐BA1.xlsx(docx) or LastFirst1‐ LastFirst2‐BA1.xlsx(docx). If you work in a two‐person team, only one submission is needed. Please make sure to include both team members’ names and GT accounts in the Word file.