Professional Documents
Culture Documents
Titanic
Titanic
load("~/R_code_&_data/titanic.raw.rdata")
head(titanic.raw)
attach(titanic.raw)
install.packages("Matrix")
library(arules)
rules = apriori(titanic.raw)
inspect(rules)
#In computer science and data mining, Apriori is a classic algorithm for learning association rules. Apriori
is designed to operate on databases containing transactions. As is common in association rule mining,
given a set of itemsets, the algorithm attempts to find subsets which are common to at least a minimum
number C of the itemsets. Apriori uses a "bottom up" approach, where frequent subsets are extended
one item at a time (a step known as candidate generation), and groups of candidates are tested against
the data. The algorithm terminates when no further successful extensions are found.
#Apriori uses breadth-first search and a tree structure to count candidate item sets efficiently. It
generates candidate item sets of length k from item sets of length k-1. Then it prunes the candidates
which have an infrequent sub pattern. According to the downward closure lemma, the candidate set
contains all frequent k-length item sets. After that, it scans the transaction database to determine
frequent item sets among the candidates.
#Apriori, while historically significant, suffers from a number of inefficiencies or trade-offs, which have
spawned other algorithms. Candidate generation generates large numbers of subsets (the algorithm
attempts to load up the candidate set with as many as possible before each scan). Bottom-up subset
exploration (essentially a breadth-first traversal of the subset lattice) finds any maximal subset S only
after all 2^{|S|}-1 of its proper subsets.
#We then set rhs=c("Survived=No", "Survived=Yes") in appearance to make sure that only
"Survived=No" and "Survived=Yes" will appear in the rhs of rules.
# rules with rhs containing "Survived" only
inspect(rules.sorted)
#In the above result, rule 2 provides no extra knowledge in addition to rule 1, since rules 1 tells us that
all 2nd-class children survived.
#Generally speaking, when a rule (such as rule 2) is a super rule of another rule (such as rule 1) and the
former has the same or a lower lift,
#the former rule (rule 2) is considered to be redundant. Below we prune redundant rules.
which(redundant)
[1] 2 4 7 8
inspect(rules.pruned)
#Package arulesViz supports visualization of association rules with scatter plot, balloon plot, graph,
parallel coordinates plot, etc.
install.packages( arules , scatterplot3d, vcd, seriation, igraph,"grid","cluster","TSP","gclus", "colorspace")
install.packages("arulesViz")
library(arulesViz)
plot(rules.pruned)
library(readxl)
"numeric", "numeric"))
inspect(aa)
"C:/Users/Rohan Bhosale/Documents/pro2/proo/Prof.xlsx"