0% found this document useful (0 votes)
1 views77 pages

R Lab PGM

The document outlines various R programming exercises, including calculating the sum, mean, and product of vectors, sorting vectors, and checking for prime numbers. It also covers data handling techniques such as converting table data into data frames and performing operations like K-Means clustering. Each exercise includes an aim, algorithm, and sample program code with expected outputs.

Uploaded by

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

R Lab PGM

The document outlines various R programming exercises, including calculating the sum, mean, and product of vectors, sorting vectors, and checking for prime numbers. It also covers data handling techniques such as converting table data into data frames and performing operations like K-Means clustering. Each exercise includes an aim, algorithm, and sample program code with expected outputs.

Uploaded by

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

INDEX

R TOOL

S. Date Contents Page Sign


No No
1 20.01.2025 Sum ,Mean and Product of Vector
2 20.01.2025 Population
3 23.01.2025 Sort a vector
4 23.01.2025 Matrix
5 23.01.2025 Sequence
6 28.01.2025 Table data into Data frame
7 28.01.2025 Student data into Data frame
8 31.01.2025 Prime number
9 31.01.2025 Leap year
10 31.01.2025 Odd or even
11 05.02.2025 Sum of natural numbers
12 05.02.2025 Decimal into binary
13 10.02.2025 Factorial of a number
14 10.02.2025 Simple calculator
15 10.02.2025 Import CSV data into R
16 14.02.2025 Move the result data R to CSV
17 14.02.2025 Line graph For Student Data
18 19.02.2025 Pie-chart For Employee Data
19 19.02.2025 Existing data set in R and draw the
chart
20 21.02.2025 K-Means Algorithm for IRIS data
set
21 21.02.2025 MTcar data set and perform analysis
WEGA TOOL

S. No Date Contents Page Sign


No
1 preprocessing on dataset student

2 preprocessing on dataset labor

3 Association rule process on


dataset contactlenses

4 Association rule process on


dataset test

5 classification rule process on


dataset student using j48
algorithm

6 process on dataset employee


using j48 algorithm

7 classification rule process on


dataset employee using id3
algorithm

8 classification rule process on


dataset employee using naïve
bayes algorithm

9 clustering rule process on dataset


iris.arff using simple k-means

10 Clustering rule process on dataset


student.arff using simple kmeans
EX.No:1
Sum ,Mean and Product of Vector in R
Date:20.01.2025

Aim:
To Write a R program to find Sum, Mean and Product of Vector in R.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Use the functions sum (), mean (), product () to calculate the vector.

Step 4: Save the program.

Step 5: Run the program in the R Console using source (“E:\\ R tool\\smp.r")

Step 6: Display the result


Program:

print("Find Sum, Mean and Product of Vector


Vecto in R")
print("-----------------------------------------
-----------------------------------------")
n<-as.integer(readline("enter
as.integer(readline("enter the number of elements : "))
a<-c()
cat("enter the ",n,"numbers:")
for (i in (1:n))
{
a<-c(a,as.integer(readline()))
c(a,as.integer(readline()))
}
# Print results
cat("Sum of the vector:", sum(a),
sum(a
"\nMean
nMean of the vecror:", mean(a),
"\nProduct:", prod(a), "\n")

Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:2 Sample from a Population
Date:20.01.2025

Aim:

To Write a R program to sample from a Population.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the values of the population.

Step 4: Use the dataframe() function to create dataframe() of the given values.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\pop.r").

Step 7: Print the result.


Program:

print("sample form a population")


print("------------------------")
n<-as.integer(readline("enter the number of samples : "))
data<-c()
cat("enter the ",n,"samples:")
for (i in (1:n))
{
data<-c(data,as.integer(readline()))
}
cat("given Sample : ",data,"\n")
z<-as.integer(readline("enter the number of samples : "))
cat(sample(data,z),"\n")

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:3 Sort a Vector
Date:23.01.2025

Aim:

To Write an R program to Sort a Vector in R.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the values to a variable.

Step 4: Use inbuild sort () function to sort a values.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\sort.r").

Step 7: Print the result.


Program:

print("Sort a Vector in R")


print("------------------")
n<-as.integer(readline("enter
as.integer(readline("enter the number of elements : "))
a<-c()
cat("enter the ",n,"numbers:")
for (i in (1:n))
{
a<-c(a,as.integer(readline()))
}
cat(" Given elements in sorted in Asending order :","
:","\n",sort(a))
cat("\nn Given elements in sorted in Decending order :","
:","\n",sort(a,decreasing=TRUE),"
n",sort(a,decreasing=TRUE),"\n")

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:4
combine the matrix using rbind and cbind methods
Date:23.01.2025

Aim:

To Write a R program to combine the matrix using rbind and cbind .

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Declare with the parameters of the matrix.

Step 4: Use the inbuild cbind(),rbind() function to combine the matrix.

Step 5: Save the program.

Step 6: Run the program for R Console using source (“E:\\ R tool\\matrix.r").

Step 7: Print the result.


Program:
print("combine the matrix using rbind and cbind methods.")

m1<- matrix(c(20:28),nrow=3,ncol=3,byrow=TRUE)
m2<- matrix(c(30:38),nrow=3,ncol=3,byrow=TRUE)

x<- cbind(m1,m2)
y<- rbind(m1,m2)

cat("\n \t First matrix","\n")


print(m1)

cat("\n \t Second matrix","\n")


print(m2)

cat("\n \t Column matrix","\n")


print(x)

cat("\n \t Row matrix","\n")


print(y)
Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:5
Use seq() to create sequence
Date:23.01.2025

Aim:

To Write a R program to Use seq() to create sequence.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the input of the variable.

Step 4: Use the inbuild seq() function to create sequence of the values.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\seq.r").

Step 7: Print the result.


Program:

print("Use seq() to create sequence in R")


print("---------------------------------
---------------------------------")

a<-as.integer(readline("enter
as.integer(readline("enter the Starting element : "))
b<-as.integer(readline("enter
as.integer(readline("enter the Ending element : "))
c<-as.integer(readline("enter
as.integer(readline("enter the increasing element : "))

cat(seq(a,b,c),"\n")

Output:

Result:

Thus the above program has been executed and verified successfully.
successfu
EX.No:6
convert the table data into data frame
Date:28.01.2025

Aim:

To Write a R program to convert the table data into data frame.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the input for the table data.

Step 4: Use the dataframe() function to convert table data to data frame.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\data.r").

Step 7: Stop the program


Program:
print("Employee Details Using DataFrame")
print("--------------------------------
--------------------------------")

n <- as.integer(readline("Enter the number of employees = "))

empno <- c()


ename <- c()
sal <- c()

for(i in (1:n)) {
empno <- c(empno, as.integer(readline("Enter the employee number = ")))
ename <- c(ename, readline("Enter the employee name = "))
sal <- c(sal, as.integer(readline("Enter the salary = ")))
}

empdata <- data.frame("EMP.NO" = empno, "EMP.NAME" = ename, "SALARY" = sal)


print(empdata)

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:7 Calculate student mark list and output it in data frame
Date:28.01.2025

Aim:

To Write a R program to calculate student mark list and output in data

frame.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the input of the student values.

Step 4: Use the dataframe() function to calculate student mark list and

output in data frame.

Step 5: Save the program.

Step 6: Run the program for R Console using source (“E:\\ R tool\\student.r").

Step 7: Print the result.


Program:

print("DATA FRAME")

n <- as.integer(readline("Enter the Number = "))

rno <- c()


name <- c()
m1 <- c()
m2 <- c()
m3 <- c()

for (i in (1:n)) {
rno <- c(rno, as.integer(readline("Enter Register No = ")))
name <- c(name, readline("Enter Name = "))
m1 <- c(m1, as.integer(readline("Enter M1 = ")))
m2 <- c(m2, as.integer(readline("Enter M2 = ")))
m3 <- c(m3, as.integer(readline("Enter M3 = "))) }

total <- m1 + m2 + m3
avg <- total / 3

x <- data.frame("\tREGISTER_NO" = rno,


"\tNAME" = name,
"\tMARK1" = m1,
"\tMARK2" = m2,
"\tMARK3" = m3,
"\tTOTAL" = total,
"\tAVG" = avg)

print(x)
Output:

Result:
Thus the above program has been executed and verified.
verified
EX.No:8 Check Prime Number
Date:31.01.2025

Aim:

To Write a R program to Check Prime Number.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: create a function named Find_prime_Num() to Check the prime

Number.

Step 4: Use for loop to check the prime Number.

Step 5: Save the program.

Step 6: Run the program for R Console using source (“E:\\ R tool\\prime.r").

Step 7: Print the result.


Program:

print("Prime Number Checking")


print("=======================")

n <- as.integer(readline("Enter the number = "))

if (n <= 1)
{
print(paste("Given number", n, "is neither prime nor composite."))
} else if (n == 2)
{
print(paste("Given number", n, "is the only even prime number."))
} else if (any(n %% 2:(n-1)
2:(n == 0))
{
print(paste("Given number", n, "is not Prime."))
} else
{
print(paste("Given number", n, "is Prime."))

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:9 Check for Leap Year
Date:31.01.2025

Aim:

To Write a R program to Check for Leap Year.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Create a function is_leap_year() to check leap year.

Step 4: Use if..else() to check given year is leap year or not.

Step 5: Save the program.

Step 6: Run the program for R Console using source (“E:\\ R tool\\leep.r").

Step 7: Print the result.


Program:

print("Leap Year Checking")


print("------------------")

n <- as.integer(readline("Enter a year: "))

if ((n %% 4 == 0) && ((n %% 100 != 0) || (n %% 400 == 0))) {


print(paste(n, "is a Leap Year"))
} else {
print(paste(n,
n, "is not a Leap Year"))
}

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:10 Check if a Number is Odd or Even
Date:31.01.2025

Aim:

To Write a R program to Check if a Number is Odd or Even.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the input for variables.

Step 4: use shift operator to check the given number is odd or even.

Step 5: Save the program.

Step 6: Run the program for R Console using source (“E:\\ R tool\\odd.r").

Step 7: Print the result.


Program:

print("ODD OR EVEN")
print("-----------")

a <- as.integer(readline("Enter a value: "))

if (a %% 2 == 0)
{
cat("Given number", a, "is Even.\n")
Even.
} else
{
cat("Given number", a, "is Odd.\n")
Odd.

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:11 Find the Sum of Natural Numbers
Date:05.02.2025

Aim:

To Write a R program to Find the Sum of Natural Numbers.

Algorithm:

Step1: Start the program.

Step2: Open the R-GUI and click the New Script to type the program.

Step3: create a function named sum_of_number().

Step4: Use while() loop to find the sum of Natural Numbers.

Step5: Save the program.

Step 6: Run the program in R Console using source (“E:\\ R tool\\natural.r").

Step 7: Print the result.


Program:
n<-as.integer(readline("enter
as.integer(readline("enter the number : "))

if(n < 0)
{
print("Enter a positive number")
} else
{
sum = (n*(n+1))/2;
print(paste("The sum
um is", sum))
}

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:12 Convert Decimal into Binary using Recursion
Date:05.02.2025

Aim:

To Write a R program to Convert Decimal into Binary using Recursion.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: create a function convert_to_binary().

Step 4: Use convert_to_binary() function to convert decimal to binary.

Step 5: Save & Run the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\binary.r").

Step 7: Print the result.


Program:

print("Convert Decimal to Binary \n")


print("------------------------")
")

b<- function(d)
{
if(d > 1)
b(d%/%2)
cat(d %% 2)
}

n<-as.integer(readline("enter
as.integer(readline("enter the number : "))
cat(b(a),"binary value for the ",n,"
",n,"\n")

Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:13 Find the Factorial of a Number Using Recursion
Date:10.02.2025

Aim:

To Write a R program to Find the factorial of a Number Using Recursion.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Create a function recur_factorial().

Step 4: Use the if..else() function to find a factorial.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\fact.r").

Step 7: Print the result.


Program:

n<-as.integer(readline("enter
as.integer(readline("enter the number : "))

fact <- function(n)


{
if(n <= 1)
{
return(1)
} else
{
return(n * fact(n-1))
}
}
cat("Factorial number is : ",fact(n),"\n")
",fact(n),"

Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:14 Make a Simple Calculator
Date: 10.02.2025

Aim:

To Write a R program to Make a Simple Calculator.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Create a function add(),subtract(),multiply(),divide().

Step 4: Use the switch statement to create a simple calculator.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\calc.r").

Step 7: Print the result.


Program:

# Load the tcltk package


if (!require("tcltk")) install.packages("tcltk")
library(tcltk)

# Function to perform calculations


calculate <- function() {
num1 <- as.numeric(tclvalue(num1_var))
num2 <- as.numeric(tclvalue(num2_var))
operation <- tclvalue(operation_var)

result <- switch(operation,


"Addition" = num1 + num2,
"Subtraction" = num1 - num2,
"Multiplication" = num1 * num2,
"Division" = num1 / num2)

tclvalue(result_var) <- paste("Result:", result)


}

# Create the main window


window <- tktoplevel()
tkwm.title(window, "Simple Calculator")

# Create input fields


num1_var <- tclVar("0")
num2_var <- tclVar("0")
operation_var <- tclVar("Addition")
result_var <- tclVar("Result: ")
# Create GUI elements
tkgrid(tklabel(window, text = "Enter first number:"), padx = 10, pady = 10)
num1_entry <- tkentry(window, textvariable = num1_var)
tkgrid(num1_entry, padx = 10, pady = 10)

tkgrid(tklabel(window, text = "Enter second number:"), padx = 10, pady = 10)


num2_entry <- tkentry(window, textvariable = num2_var)
tkgrid(num2_entry, padx = 10, pady = 10)

tkgrid(tklabel(window, text = "Select operation:"), padx = 10, pady = 10)


operation_menu <- ttkcombobox(window, values = c("Addition", "Subtraction",
"Multiplication", "Division"), textvariable = operation_var)
tkgrid(operation_menu, padx = 10, pady = 10)

# Create a button to calculate


calculate_button <- tkbutton(window, text = "Calculate", command = calculate)
tkgrid(calculate_button, padx = 10, pady = 10)

# Display the result


result_label <- tklabel(window, textvariable = result_var)
tkgrid(result_label, padx = 10, pady = 10)

# Run the GUI


tkfocus(window)
Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:15 Import CSV data into R
Date:10.02.2025

Aim:

To Write a R program to import CSV data into R.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: open notepad and type the student values and save with std.csv file

format.

Step 4: give the path of the csv file and import the csv file.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\csv.r").

Step 7: Print the result.


Program:

print("R Program to import CSV data into R.")


print("____________________________________")

x<-read.csv("E:\\msc\\MSC
MSC 2nd sem
sem\\DM LAB\\R tool\\std.csv")
print(x)

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:16 Move the result data from R to CSV
Date: 14.02.2025

Aim:

To Write a R program to move the result data from R to CSV.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Type the program to export std.csv file in specific directory.

Step 4: use csv.write() to write the data into csv file.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\calc.r").

Step 7: Print the result.


Program:
print("Employee Details move the result data from R to CSV.")
print("----------------------------------------------------")

n <- as.integer(readline("Enter the number of employees = "))

empno <- c()


ename <- c()
sal <- c()

for(i in (1:n))
{
empno <- c(empno, as.integer(readline("Enter the employee number = ")))
ename <- c(ename, readline("Enter the employee name = "))
sal <- c(sal, as.integer(readline("Enter the salary = ")))
da<-0.40*sal
ma<-0.10*sal
gpay<-sal+da+ma
}

df <- data.frame("EMP.NO" = empno, "EMP.NAME" = ename, "SALARY" =


sal,"DA"=da,"MA"=ma,"GROSSPAY"=gpay)
print(df)

write.csv(df,"E:\\msc\\MSC 2nd sem\\DM LAB\\R tool\\employee.csv")

print("employee details moved csv file in sucessfully")


Output:

Result:

Thus
hus the above program has been executed and verified successfully.
EX.No:17
Line Graph for Student Data
Date: 14.02.2025

Aim:

To Write a R program to Draw the Line Graph for Student Data.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the range for the subject & give the marks.

Step 4: Use plot to display the Line graph.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\line.r").

Step 7: Print the result.


Program:

print("LINE GRAPH USING DATA FRAME")


n <- as.integer(readline("Enter the Number of marks = "))
m <- c()
cat("enter the ",n,"marks")
for (i in (1:n))
{
m<- c(m, as.integer(readline()))
}
plot(m,xlab="Students",ylab="Mar
plot(m,xlab="Students",ylab="Marks",main="MarkAnalysis",type="l",col="black")
ks",main="MarkAnalysis",type="l",col="black")

Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:18 Pie-Chart for Employee Data
Date: 19.02.2025

Aim:

To Write a R program to Draw the Pie-Chart for Employee Data.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click the New Script to type the program.

Step 3: Give the input for salary & employee name for label variable.

Step 4: Use pie to display the pie-chart for employee data.

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\pie.r").

Step 7: Print the result.


Program:

print("-----PIE CHART-----")
n <- as.integer(readline("Enter no. of employees: "))
emp <- c()
name <- c()
# Input: Employee details
for (i in 1:n) {
cat("Enter details of Employee", i, ":\n")
name <- c(name, readline("Name: "))
emp <- c(emp, as.integer(readline("Salary: ")))
}
# Generate colors for each employee
colors <- rainbow(n)
pie(emp, main = "SALARY DETAILS", labels = name, col = colors)

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:19 Existing dataset and draw a chart.
Date: 19.02.2025

Aim:

To write an R program to create a table from an existing dataset and draw

a chart.

Algorithm:

Step 1: Start the program.

Step 2: Load or use an existing dataset in R.

Step 3: Create a table using the table() function based on selected variables.

Step 4: Visualize the table data using appropriate chart types (e.g., bar plot or
pie chart).

Step 5: Save the program.

Step 6: Run the program in the R Console using source (“E:\\ R tool\\pie.r").

Step 7: Print the result.

.
Program:

# Program to plot the AirPassengers dataset in R


print("Existing Dataset in R")
print("---------------------")

# Plot the AirPassengers dataset


plot(
AirPassengers,
xlab = "Years",
ylab = "No. of Passengers",
main = "AirPassengers Analysis",
type = "l", # Line plot
col = "purple" # Color of the line
)

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:20 K-Means Clustering on IRIS Dataset
Date: 21.02.2025

Aim:

To write an R program to apply the K-Means algorithm on the Iris dataset

and visualize the output.

Algorithm:

Step 1: Start the program.

Step 2: Load the Iris dataset using the data() function.

Step 3: Select numeric columns for clustering (e.g., Sepal.Length and

Sepal.Width).

Step 4: Apply the K-Means algorithm using the kmeans() function.

Step 5: Plot the clusters using a scatter plot to visualize the results.

Step 6: Run the program in the R Console using source (“E:\\ R

tool\\iris.r").

Step 7: Print the result.


Program:

# Program: Clustering for the Iris Dataset

print("CLUSTERING For IRIS DATASET")


print("---------------------------")

# Load the Iris dataset and select the relevant columns


dat <- iris[, c(1, 2, 3, 4)]

# Perform k-means clustering with 3 clusters


res <- kmeans(dat, 3)

# Set up a 2x2 plotting area


par(mfrow = c(2, 2))

# Plot the clustering results for different column pairs


plot(dat[c(1, 2)], col = res$cluster, main = "Clustering on Sepal Dimensions")
plot(dat[c(3, 4)], col = res$cluster, main = "Clustering on Petal Dimensions")

Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:21 mtcar data set and perform analysis
Date: 21.02.2025

Aim:

To write an R program to import CSV data and analyze it using basic

statistical functions.

Algorithm:

Step 1: Start the program.

Step 2: Open the R-GUI and click "New Script" to create a new file.

Step 3: Create a CSV file (e.g., mtcars_data.csv) using any text editor or

spreadsheet software.

Step 4: Save the file and specify its path in the R program.

Step 5: Use read.csv() to load the data into R.

Step 6; Perform basic statistical analysis on the imported dataset.

Step 7: Visualize the data using graphs (e.g., histogram or scatter plot).
Program:

# Importing the dataset


file_path <- "path_to_your_file/mtcars_data.csv" # Replace with the actual path
mtcars_data <- read.csv(file_path)

# Display first few rows


print(head(mtcars_data))

# Basic statistical analysis


summary(mtcars_data)

# Drawing a histogram for mpg


hist(mtcars_data$mpg, main = "Histogram of MPG", xlab = "Miles Per Gallon", col =
"green", border = "blue")

# Scatter plot for mpg vs hp


plot(mtcars_data$mpg, mtcars_data$hp, main = "MPG vs HP", xlab = "Miles Per
Gallon", ylab = "Horsepower", col = "red")

Output:
Result:
Thus the above program has been executed and verified successfully.
WEKA TOOL
EX.No:1 Preprocessing on dataset student.arff
DATE:26.02.2025

Aim:

To demonstrate the preprocessing of the student.arff dataset using

the WEKA tool.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset student.arff into WEKA by clicking the "Open

file" button.

Step 4: Use the "Preprocess" tab to select and apply filters like "Remove",

"Normalize", or "Replace Missing Values".

Step 5: Save the preprocessed dataset if required.

Step 6: Display the result.


Program:

@relation student
@attribute sid numeric
@attribute name {ajai,bala,karthi,janaki,jeya,vijaya}
@attribute S1 numeric
@attribute S2 numeric
@attribute S3 numeric
@attribute S4 numeric
@attribute S5 numeric
@attribute total numeric
@attribute result {pass,fail}

@data
1,ajai,60,55,45,50,40,250,pass
2,bala,60,55,45,40,40,240,pass
3,karthi,60,55,40,50,40,240,pass
4,janaki,60,55,30,50,40,235,fail
5,jeya,60,55,45,60,40,260,pass
6,vijaya,60,55,65,50,40,270,pass

Output:
Result:

Thus the above program has been executed and verified successfully.
EX.No:2 Preprocessing on dataset labor.arff
DATE: 26.02.2025

Aim:

To demonstrate the preprocessing of the labor.arff dataset using the

WEKA tool.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset labor.arff into WEKA by clicking the "Open file"

button.

Step 4: Use the "Preprocess" tab to view the attributes and missing values.

Step 5: Apply filters like "Discredited", "Normalize", or "Replace Missing

Values".

Step 6: Save the preprocessed dataset if required.

Step 7: Print the result.


Program:

@relation labour
@attribute eid numeric
@attribute name string
@attribute gender string
@attribute age numeric
@attribute working_hours numeric
@attribute shift {day,night}
@attribute sal numeric
@attribute education_allow {yes,no}

@data
101,suresh,male,45,8,day,18500,yes
102,anitha,female,37,6,day,25800,no
103,divya,female,28,6,night,26750,yes
104,jeya,female,30,8,day,28800,yes
105,ajith,male,38,6,night,35000,no
106,pradeep,male,28,8,day,25000,yes

Output:
Result:
Thus the above program has been executed and verified successfully.
EX.No:3 Association rule process on dataset contact
Date: 03.03.2025 lenses.arff using apriori algorithm

Aim:
To demonstrate the association rule mining on the contactlenses.arff
dataset using the Apriori algorithm in WEKA.

Algorithm:

Step 1: Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset contactlenses.arff by clicking the "Open file" button.

Step 4: Navigate to the "Associate" tab.

Step 5: Select the "Apriori" algorithm from the available list.

Step 6: Configure the parameters for support and confidence thresholds.

Step 7: Click on the "Start" button to generate association rules.

Step 8: Review the generated rules.

Step 9: Print the result.


Program:

@relation contact-lenses
@attribute age {young, pre-presbyopic, presbyopic}
@attribute spectacle-prescrip {myope, hypermetrope}
@attribute astigmatim {no, yes}
@attribute tear-prod-rate {reduced, normal}
@attribute contact-lenses {soft, hard, none}

@data
young,myope,no,reduced,none
young,myope,no,normal,soft
young,myope,yes,normal,hard
young,hypermetrope,no,normal,soft
young,hypermetrope,yes,normal,hard
pre-presbyopic,myope,no,normal,soft
pre-presbyopic,myope,yes,normal,hard
pre-presbyopic,hypermetrope,no,normal,soft
pre-presbyopic,hypermetrope,yes,normal,hard
presbyopic,myope,no,normal,none
presbyopic,myope,yes,normal,hard
presbyopic,hypermetrope,no,normal,soft
presbyopic,hypermetrope,yes,normal,hard
Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:4
Association Rule Process on Dataset test.arff
DATE: 03.03.2025 Using Apriori Algorithm

Aim:

To demonstrate the association rule mining on the test.arff dataset using

the Apriori algorithm in WEKA.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset test.arff by clicking the "Open file" button.

Step 4: Navigate to the "Associate" tab.

Step 5:Select the "Apriori" algorithm from the list of options.

Step 6: Configure the parameters for support and confidence thresholds.

Step 7: Click the "Start" button to execute the algorithm and generate rules.

Step 8: Analyze the generated rules.

Step 9: Print the result.


Program:

@relation attribute
@attribute bread{y,n}
@attribute jelly{y,n}
@attribute butter{y,n}
@attribute milk{y,n}
@attribute sugar{y,n}
@data
yyynn
ynynn
ynyyn
ynnyy
yynyn

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:5
DATE: 03.03.2025
Classification Rule Process on Dataset
student.arff Using J48 Algorithm

Aim:

To demonstrate the classification rule mining on the student.arff dataset

using the J48 algorithm in WEKA.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset student.arff by clicking the "Open file" button.

Step 4: Navigate to the "Classify" tab.

Step 5:Select the J48 algorithm from the classifier list.

Step 6: Configure the test options, such as cross-validation or percentage split.

Step 7: Click the "Start" button to train and evaluate the classifier.

Step 8: Review the generated decision tree and performance metrics.

Step 9: Print the result.


Program:

@relation student
@attribute age {<30,30-40,>40}
@attribute income {low,medium,high}
@attribute student {yes,no}
@attribute credit-rating {fair,excellent}
@attribute buyspc {yes,no}

@data
%
<30, high, no, fair, no
<30, high, no, excellent, no
30-40, high, no, fair, yes
>40, medium, no, fair, yes
>40, low, yes, fair, yes
>40, low, yes, excellent, no
30-40, low, yes, excellent, yes
<30, medium, no, fair, no
<30, low, yes, fair, no
>40, medium, yes, fair, yes
<30, medium, yes, excellent, yes
30-40, medium, no, excellent, yes
30-40, high, yes, fair, yes
>40, medium, no, excellent, no
%
Output:

Result:

Thus the above program has been executed and verified successfully.
EX.No:6
Classification Rule Process on Dataset
DATE: employee.arff Using J48 Algorithm

Aim:
To demonstrate the classification rule mining on the employee.arff dataset using
the J48 algorithm in WEKA.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset employee.arff by clicking the "Open file" button.

Step 4: Navigate to the "Classify" tab.

Step 5:Select the J48 algorithm from the classifier list.

Step 6: Configure the test options, such as cross-validation or percentage split.

Step 7: Click the "Start" button to execute the algorithm.

Step 8: Review the generated decision tree and performance metrics.

Step 9: Stop the program


Program:
@relation employee
@attribute age{25,27,28,29,30,35,48}
@attribute salary{10k,15k,17k,20k,25k,30k,35k,32k}
@attribute performance{good,average,poor}
@data
25 10k poor
27 15k poor
27 17k poor
28 17k poor
29 20k average
30 25k average
29 25k average
30 20k average
35 32k good
35 35k good
48 32k good

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:7
DATE: Classification Rule Process on Dataset
employee.arff Using ID3 Algorithm

Aim:

To demonstrate the classification rule mining on the employee.arff dataset

using the ID3 algorithm in WEKA.

Algorithm:

Step 1:Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset employee.arff by clicking the "Open file"

button.

Step 4: Navigate to the "Classify" tab.

Step 5:Select the ID3 algorithm from the classifier list.

Step 6: Configure the test options, such as cross-validation or percentage

split.

Step 7: Click the "Start" button to execute the algorithm.

Step 8: Review the generated decision tree and performance metrics.

Step 9: Stop the program.


Program:

Data set
@relation employee
@attribute age{25,27,28,29,30,35,48}
@attribute salary{10k,15k,17k,20k,25k,30k,35k,32k}
@attribute performance{good,average,poor}
@data
25 10k poor
27 15k poor
27 17k poor
28 17k poor
29 20k average
30 25k average
29 25k average
30 20k average
35 32k good
35 35k good
48 32k good

Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:8 Classification Rule Process on Dataset
DATE: employee.arff Using Naïve Bayes Algorithm

Aim:

To demonstrate the classification rule mining on the employee.arff dataset using

the Naïve Bayes algorithm in WEKA.

Algorithm:

Step 1: Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset employee.arff by clicking the "Open file" button.

Step 4: Navigate to the "Classify" tab.

Step 5: Select the Naïve Bayes algorithm from the classifier list.

Step 6: Configure the test options, such as cross-validation or percentage split.

Step 7: Click the "Start" button to execute the algorithm.

Step 8: Review the classification results and performance metrics.

Step 9: Stop the program.


Program:

@relation employee
@attribute age{25,27,28,29,30,35,48}
@attribute salary{10k,15k,17k,20k,25k,30k,35k,32k}
@attribute performance{good,average,poor}
@data
25 10k poor
27 15k poor
27 17k poor
28 17k poor
29 20k average
30 25k average
29 25k average
30 20k average
35 32k good
35 35k good
48 32k good
Output:

Result:
Thus the above program has been executed and verified successfully.
EX.No:9 Classification Rule Process on Dataset
DATE: employee.arff Using Naïve Bayes Algorithm

Aim:

To demonstrate clustering on the iris.arff dataset using the Simple K-Means

algorithm in WEKA.

Algorithm:

Step 1: Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset iris.arff by clicking the "Open file" button.

Step 4: Navigate to the "Cluster" tab.

Step 5: Select the Simple K-Means algorithm from the list of clustering

algorithms.

Step 6: Configure the number of clusters to 3 (for the iris dataset) and other

parameters as needed.

Step 7: Click the "Start" button to execute the clustering process.

Step 8: Analyze the cluster assignments and other outputs.

Step 9: Stop the program


Program:

@RELATION iris
@ATTRIBUTE sepallength REAL
@ATTRIBUTE sepalwidth REAL
@ATTRIBUTE petallength
tallength REAL
@ATTRIBUTE petalwidth REAL
@ATTRIBUTE class {Iris-setosa,Iris
setosa,Iris-versicolor,Iris-virginica}
@DATA
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa

Output:

Result:
Thus the above program has been executed and verified
successfully.
EX.No:10
DATE: Clustering Rule Process on Dataset student.arff
Using Simple K-Means

Aim:

To demonstrate clustering on the student.arff dataset using the Simple K-

Means algorithm in WEKA.

Algorithm:

Step 1: Start the program.

Step 2: Open the WEKA GUI Chooser and click the Explorer option.

Step 3: Load the dataset student.arff by clicking the "Open file" button.

Step 4: Navigate to the "Cluster" tab.

Step 5: Select the Simple K-Means algorithm from the list of clustering

algorithms.

Step 6: Configure the number of clusters and other parameters as required.

Step 7: Click the "Start" button to execute the clustering process.

Step 8: Analyze the clustering results, including the centroids and cluster

assignments.

Step 9: Stop the program.


Program:

@relation student
@attribute sid numeric
@attribute name {usha,hari,rajesh,kiran,giri,manash}
@attribute DM numeric
@attribute WT numeric
@attribute CN numeric
@attribute AI numeric
@attribute STM numeric
@attribute total numeric
@attribute result {pass,fail}
@data
1,usha,60,55,45,50,40,250,pass
2,hari,60,55,45,40,40,240,pass
3,rajesh,60,55,40,50,40,240,pass
4,kiran,60,55,30,50,40,235,fail
2,giri,60,55,45,60,40,260,pass
3,manash,60,55,65,50,40,270,pass

Output:

Result:
Thus the above program has been executed and verified
successfully.
Filename: INDEX
Directory: C:\Users\lenovo\OneDrive\Documents
Template: C:\Users\lenovo\AppData\Roaming\Microsoft\Templates\Normal.dotm
Title:
Subject:
Author: lenovo
Keywords:
Comments:
Creation Date: 1/21/2025 7:44:00 PM
Change Number: 35
Last Saved On: 3/11/2025 6:56:00 AM
Last Saved By: lenovo
Total Editing Time: 346 Minutes
Last Printed On: 3/11/2025 6:57:00 AM
As of Last Complete Printing
Number of Pages: 76
Number of Words: 5,358 (approx.)
Number of Characters: 30,541 (approx.)

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