Datamining Lab Record
Datamining Lab Record
RECORD NOTE
Record work submitted to the Bharathiar University in partial fulfillment of the requirement for
the Degree of
SNMV
Bharathiar University)
ShriGambhirmalBafna Nagar,
Malumachampatti, Coimbatore-641050.
April-2023
DEPARTMENT OF COMPUTER SCIENCE
6 Linear Regression.
7 Data Visualization
Ex No.01 APRIORI ALGORITHM
DATE:
Aim:
To implement the apriori algorithm to extract the association rule using the R tool.
Algorithm:
STEP 4: Create a notepad with n number of transactions & save the fill with txt format.
>library("arules");
>library("arulesViz");
>patterns = random.patterns(nItems = 1000);
>summary(patterns);
>trans = random.transactions(nItems = 1000, nTrans = 1000, method = "agrawal", patterns = patterns);
>image(trans);
>data("AdultUCI");
>Adult = as(AdultUCI, "transactions");
>rules = apriori(Adult, parameter=list(support=0.01, confidence=0.5));
>rules;
>inspect(head(sort(rules, by="lift"),3));
>plot(rules);
>head(quality(rules));
>plot(rules, measure=c("support","lift"), shading="confidence");
>plot(rules, shading="order", control=list(main ="Two-key plot"));
OUTPUT
>sel = plot(rules, measure=c("support","lift"), shading="confidence", interactive=TRUE);
>subrules = rules[quality(rules)$confidence > 0.8];
>subrules
OUTPUT
OUTPUT
RESULT:
Aim:
Algorithm:
STEP 3: Open notepad and mark details and save the file as text document.
OUTPUT
Cluster means:
Sepal.Length Sepal.Width Petal.Length Petal.Width
1 5.175758 3.624242 1.472727 0.2727273
2 6.314583 2.895833 4.973958 1.7031250
3 4.738095 2.904762 1.790476 0.3523810
Clustering vector:
[1] 1 3 3 3 1 1 1 1 3 3 1 1 3 3 1 1 1 1 1 1 1 1 1 1 3 3 1 1 1 3 3 1 1 1 3 1 1
[38] 1 3 1 1 3 3 1 1 3 1 3 1 1 2 2 2 2 2 2 2 3 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2
[75] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 3 2 2 2 2 2 2 2 2 2 2 2 2
[112] 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2
[149] 2 2
Available components:
OUTPUT
1 2 3
setosa 33 0 17
versicolor 0 46 4
virginica 0 50 0
OUTPUT
> points(kc$centers[,c("Sepal.Length", "Sepal.Width")], col=1:3, pch=8, cex=2)
RESULT:
DATE:
Aim:
To implement hierarchical clustering using R tool.
Algorithm:
>hc=hclust(dist(mtcars),method=”ave”)
>plot(hc)
OUTPUT
RESULT:
DATE:
Aim:
Algorithm:
> library(e1071)
> local({pkg <- select.list(sort(.packages(all.available = TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
> library(MASS)
> data(cats)
> model <- svm(Sex~., data = cats)
> print(model)
OUTPUT
Call:
svm(formula = Sex ~ ., data = cats)
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 1
gamma: 0.5
> summary(model)
OUTPUT
Call:
svm(formula = Sex ~ ., data = cats)
Parameters:
SVM-Type: C-classification
SVM-Kernel: radial
cost: 1
gamma: 0.5
( 39 45 )
Number of Classes: 2
Levels:
FM
Aim:
Algorithm:
> library(rpart)
> fit <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis)
> fit2 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
+ parms = list(prior = c(.65,.35), split = "information"))
>
> fit3 <- rpart(Kyphosis ~ Age + Number + Start, data = kyphosis,
+ control = rpart.control(cp = 0.05))
> par(mfrow = c(1,2), xpd = NA)
> plot(fit)
OUTPUT
OUTPUT
> plot(fit2)
> text(fit2, use.n = TRUE)
RESULT:
Thus the program is executed successfully and the output is verified.
Ex No.06
LINEAR REGRESSION
DATE:
Aim:
Algorithm:
STEP 3: Open the notepad and mark details and save the file as a text document.
OUTPUT
[1] 1 4 9 16 25 36
> mean(y)
OUTPUT
[1] 15.16667
> var(y)
OUTPUT
[1] 178.9667
OUTPUT
> print(lm_1)
OUTPUT
Call:
lm(formula = y ~ x)
Coefficients:
(Intercept) x
-9.333 7.000
> summary(lm_1)
OUTPUT
Call:
lm(formula = y ~ x)
Residuals:
1 2 3 4 5 6
3.3333 -0.6667 -2.6667 -2.6667 -0.6667 3.3333
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -9.3333 2.8441 -3.282 0.030453 *
x 7.0000 0.7303 9.585 0.000662 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 3.055 on 4 degrees of freedom
Multiple R-squared: 0.9583, Adjusted R-squared: 0.9478
F-statistic: 91.87 on 1 and 4 DF, p-value: 0.000662
OUTPUT
RESULT:
Aim:
Algorithm:
Line Chart
>plot(AirPassengers,type="l")
OUTPUT
Bar Chart
>barplot(iris$Petal.Length) #Creating simple Bar Graph
OUTPUT
Box Plot
>boxplot(iris$Petal.Length~iris$Species)
OUTPUT
data(iris)
par(mfrow=c(2,2))
boxplot(iris$Sepal.Length,col="red")
boxplot(iris$Sepal.Length~iris$Species,col="red")
boxplot(iris$Sepal.Length~iris$Species,col=heat.colors(3))
boxplot(iris$Sepal.Length~iris$Species,col=topo.colors(3))
OUTPUT
Scatter Plot
plot(x=iris$Petal.Length) #Simple Scatter Plot
plot(x=iris$Petal.Length,y=iris$Species) #Multivariate Scatter Plot
Pie chart
>pie(table(iris$Species))
OUTPUT
iris$Species
5
4
3
1 2
0 50 100 150 1 2 3 4 5 6 7
Index iris$Petal.Length
setosa
versicolor
virginica
RESULT: