R Lab Manual
R Lab Manual
AIM:
To implement apriori algorithm to extract association rule of data mining Using R studio
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
1
PROGRAM:
library(arules)
library(arulesViz)
library(RColorBrewer)
# import dataset
data("Groceries")
inspect(rules[1:10])
type = "relative",
2
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
3
EX-NO : 2 Implement k-means clustering technique
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
4
PROGRAM:
set.seed(123)
print(kmeans_result$centers)
# Visualize clusters
plot(data, col = kmeans_result$cluster, main = "K-means Clustering", xlab = "x1", ylab = "x2")
5
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
6
EX-NO : 3 Implement any one hierarchical clustering
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
7
PROGRAM:
data(mtcars)
str(mtcars)
plot(hc, main = "Dendrogram of mtcars Dataset", xlab = "Cars", sub = "", cex = 0.6)
# View the first few rows of the dataset with cluster labels
head(mtcars)
plot(mtcars$mpg, mtcars$wt, col = clusters, pch = 19, main = "Clusters of mtcars Dataset", xlab =
"Miles/(US) gallon", ylab = "Weight (1000 lbs)")
8
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
9
EX-NO : 4 Implement classification algorithm
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
10
PROGRAM:
set.seed(123)
class <- as.factor(ifelse(x1 + x2 > 10, "A", "B")) # Binary class label
head(data)
plot(x1, x2, col = as.integer(class), pch = 19, xlab = "Feature 1", ylab = "Feature 2")
summary(model)
predictions <-
# Calculate accuracy
11
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
12
EX-NO : 5 Implement decision tree
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
13
PROGRAM:
library(rpart)
plot(model)
14
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
15
EX-NO : 6 Linear Regression
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
16
PROGRAM:
set.seed(123)
summary(model)
17
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
18
EX-NO : 7 Data Visualization
AIM:
PROCEDURE:
Step 3: Dialog box will appear. Enter filename.r and click save.
19
PROGRAM:
set.seed(123)
x <- 1:100
# Plot histogram
OUTPUT:
plot(x, y, main = "Scatter plot of x and y", xlab = "x", ylab = "y")
OUTPUT:
20
# Plot line plot
plot(x, y, type = "l", main = "Line plot of x and y", xlab = "x", ylab = "y", col = "red")
OUTPUT:
OUTPUT:
21
# Plot bar plot
barplot(table(cut(y, breaks = 5)), main = "Bar plot of y", xlab = "Bins of y", ylab = "Frequency", col =
"green")
OUTPUT:
RESULT:
Hence the program has been executed successfully and the output is verified.
22