lab-record
lab-record
List of Experiments
9. Case study on Stock Market Analysis and applications. Stock data can be 17-19
obtained from Yahoo! Finance, Google Finance. A team of students can
apply statistical modeling on the stock data to uncover hidden patterns. R
provides tools for moving averages, auto regression and time-series
analysis which forms the crux of financial applications.
10. Detect credit card fraudulent transactions - The dataset can be obtained 19-20
from Kaggle. The team will use a variety of machine learning algorithms
that will be able to discern fraudulent from non-fraudulent one.
Experiment No: 1
Installing R:
Download R:
Installing RStudio:
Download RStudio:
Installing R packages
It is a fundamental part of working with R. R packages contain pre-built functions, data sets, and
documentation that extend the capabilities of the R programming language. Here are the steps
to install R packages using the R console within RStudio:
Open RStudio:
Launch RStudio on your computer.
Open R Console:
Once RStudio is open, you'll see several panels. The left-top panel is the R Console. This is
where you can directly interact with R by typing commands.
Install a Package:
To install an R package, you'll use the install.packages() function followed by the name of the
package you want to install. For example, to install the "ggplot2" package, type the following
command in the R Console and press Enter: install.packages("ggplot2")
Experiment No: 2
Data Description
R Code
a. R Program Structure:
library(package_name)
print(result)
my_function <- function(arg1, arg2) {
return(result)
x <- 5
name <- "John"
is_valid <- TRUE
sum_result <- 3 + 7
c. File Operations in R:
Reading files
# Reading text files
data <- read.table("data.txt", header = TRUE)
Writing files
# Writing data to text file
write.table(data, "output.txt", sep = "\t", row.names = FALSE)
Experiment No: 3
Data Description:
In this example, the CSV file has two columns:
experience_years: This column represents the number of years of experience each person
has.
salary: This column contains the corresponding salary for each person based on their
experience.
Sample rows and columns
R Code
> install.packages("csv")
> library("csv")
> Salary_Dataset = read.csv(file.choose(), 1)
> Salary_Dataset
Experiment No: 4
Data Description
R Code
# Load libraries
library(dplyr)
library(missForest)
# Read dataset
data <- read.csv("data.csv")
# Data Cleaning
cleaned_data <- data %>%
distinct() %>%
select(-Irrelevant_Column)
if (missing_values > 0) {
# Data Imputation
imputed_data <- missForest(cleaned_data, verbose = TRUE)
} else {
imputed_data <- cleaned_data
}
Experiment No: 5
Data Description
In this example, the CSV file has two columns:
experience_years: This column represents the number of years of experience each person
has.
salary: This column contains the corresponding salary for each person based on their
experience.
R Code
Experiment No: 6
Data Description
R Code
Experiment No: 7
Data Description
In this example, the CSV file has two columns:
experience_years: This column represents the number of years of experience each person
has.
salary: This column contains the corresponding salary for each person based on their
experience.
R Code
Experiment No: 8
R Code
# Load the SpamAssassin dataset (replace with your actual file path)
spam_data <- read.csv("path/to/spamassassin_data.csv", stringsAsFactors = FALSE)
# Make predictions
predictions <- predict(naive_bayes_model, newdata = test_data, type = "class")
Experiment No: 9
Aim:Case study on Stock Market Analysis and applications. Stock data can be obtained from
Yahoo! Finance, Google Finance. A team of students can apply statistical modeling on the stock
data to uncover hidden patterns. R provides tools for moving averages, auto regression and
time-series analysis which forms the crux of financial applications.
Data Description
R Code
# Load required libraries
library(dplyr)
library(lubridate)
# Read the stock data CSV file (or load data from API)
stock_data <- read.csv("stock_data.csv")
Experiment No: 10
Aim: Detect credit card fraudulent transactions - The dataset can be obtained from Kaggle. The
team will use a variety of machine learning algorithms that will be able to discern fraudulent
from non-fraudulent one.
Data Description
The dataset was obtained from Kaggle
R Code
# Load required libraries
library(AnomalyDetection)
library(randomForest)
# Split data into training and testing sets (70% training, 30% testing)
set.seed(123)
train_indices <- sample(1:nrow(CreditCardFraud), 0.7 * nrow(CreditCardFraud))
train_data <- CreditCardFraud[train_indices, ]
test_data <- CreditCardFraud[-train_indices, ]
# Make predictions
predictions <- predict(rf_model, newdata = test_data)
# Calculate accuracy
accuracy <- sum(predictions == test_data$Class) / nrow(test_data)
print(paste("Accuracy score on Test Data: :", accuracy))