0% found this document useful (0 votes)
28 views4 pages

pg dm

The document outlines the implementation of various data mining techniques including the Apriori algorithm for association rule extraction, k-means clustering, hierarchical clustering, classification algorithms, decision trees, linear regression, and data visualization. It provides R code for executing the Apriori algorithm, including functions for inspecting rules, analyzing specific items, and visualizing results. Additional functions for identifying top rules by lift and confidence, as well as finding non-redundant rules, are also included.

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views4 pages

pg dm

The document outlines the implementation of various data mining techniques including the Apriori algorithm for association rule extraction, k-means clustering, hierarchical clustering, classification algorithms, decision trees, linear regression, and data visualization. It provides R code for executing the Apriori algorithm, including functions for inspecting rules, analyzing specific items, and visualizing results. Additional functions for identifying top rules by lift and confidence, as well as finding non-redundant rules, are also included.

Uploaded by

Sathya Ashok
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Implement Apriori algorithm to extract association rule of datamining.

2. Implement k-means clustering technique.

3. Implement any one Hierarchal Clustering.

4. Implement Classification algorithm.

5. Implement Decision Tree.

6. Linear Regression.

7. Data Visualization.

1. # Install and load required packages

if (!require("arules")) install.packages("arules")

if (!require("arulesViz")) install.packages("arulesViz")

library(arules)

library(arulesViz)

# Create sample transaction data

# Each row represents a transaction, and each element in the list represents items bought

sample_transactions <- list(

c("bread", "milk", "eggs"),

c("bread", "milk"),

c("milk", "eggs", "coffee"),

c("bread", "eggs"),

c("bread", "milk", "eggs", "coffee"),

c("milk", "coffee")

# Convert the list to transactions object

trans <- as(sample_transactions, "transactions")

# Run Apriori algorithm

rules <- apriori(trans,

parameter = list(

support = 0.3, # minimum support of 30%

confidence = 0.7, # minimum confidence of 70%

minlen = 2 # minimum number of items in a rule


))

# Function to display rules in a more readable format

inspect_rules <- function(rules) {

# Convert rules to data frame

rules_df <- as(rules, "data.frame")

# Add rule number

rules_df$rule_nr <- seq_len(nrow(rules_df))

# Reorder columns

rules_df <- rules_df[, c("rule_nr", "rules", "support", "confidence", "lift")]

# Round numeric columns

rules_df$support <- round(rules_df$support, 3)

rules_df$confidence <- round(rules_df$confidence, 3)

rules_df$lift <- round(rules_df$lift, 3)

return(rules_df)

# Function to analyze rules based on specific item

analyze_item_rules <- function(rules, item) {

# Rules containing the item in LHS (antecedent)

rules_lhs <- subset(rules, lhs %in% item)

cat("\nRules with", item, "in antecedent:\n")

print(inspect_rules(rules_lhs))

# Rules containing the item in RHS (consequent)

rules_rhs <- subset(rules, rhs %in% item)

cat("\nRules with", item, "in consequent:\n")

print(inspect_rules(rules_rhs))
}

# Example usage:

# View all rules

cat("All association rules:\n")

print(inspect_rules(rules))

# Analyze rules for specific item

analyze_item_rules(rules, "milk")

# Visualize rules

plot(rules, method = "graph", control = list(type = "items"))

# Additional analysis functions

# Function to find top rules by lift

top_rules_by_lift <- function(rules, n = 5) {

rules_sorted <- sort(rules, by = "lift", decreasing = TRUE)

return(head(rules_sorted, n))

# Function to find top rules by confidence

top_rules_by_confidence <- function(rules, n = 5) {

rules_sorted <- sort(rules, by = "confidence", decreasing = TRUE)

return(head(rules_sorted, n))

# Function to find redundant rules

find_redundant_rules <- function(rules) {

# Find redundant rules

redundant <- is.redundant(rules)


# Return non-redundant rules

return(rules[!redundant])

# Example of how to use these functions:

cat("\nTop 5 rules by lift:\n")

print(inspect_rules(top_rules_by_lift(rules)))

cat("\nTop 5 rules by confidence:\n")

print(inspect_rules(top_rules_by_confidence(rules)))

cat("\nNon-redundant rules:\n")

print(inspect_rules(find_redundant_rules(rules)))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy