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

All Programs

The document outlines a series of data analysis techniques using R, including data cleaning, various types of regression (linear, multiple, logistic), decision trees, KNN, ARIMA for time series, and Naive Bayes. Each section provides code snippets for importing data, modeling, making predictions, and evaluating results with confusion matrices or summaries. It concludes with a tip highlighting the common structure of R lab programs.

Uploaded by

CHUPA RUSTOM
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)
3 views4 pages

All Programs

The document outlines a series of data analysis techniques using R, including data cleaning, various types of regression (linear, multiple, logistic), decision trees, KNN, ARIMA for time series, and Naive Bayes. Each section provides code snippets for importing data, modeling, making predictions, and evaluating results with confusion matrices or summaries. It concludes with a tip highlighting the common structure of R lab programs.

Uploaded by

CHUPA RUSTOM
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

1.

Data Cleaning

#Import dataset

data <- [Link]("[Link]")

#View data

View(data)

#Structure

str(data)

#Check missing values

sum([Link](data))

#Remove missing values

data <- [Link](data)

#Summary of data

summary(data)

2. Graphs

data <- [Link]("[Link]")

#Histogram

hist(data$Age)

#Bar graph

barplot(table(data$Result))

#Scatter plot

plot(data$Age,data$Income)

#Box plot

boxplot(data$Income)

3. Linear Regression

data <- [Link]("[Link]")

#Model

model <- lm(Sales ~ Advertising,data=data)

#Summary

summary(model)

#Prediction

predict(model,data)
4. Multiple Regression

data <- [Link]("[Link]")

#Model

model <- lm(Sales ~ Advertising + Price + Income,data=data)

#Summary

summary(model)

#Prediction

predict(model,data)

5. Logistic Regression

data <- [Link]("[Link]")

#Model

model <- glm(Result~.,data=data,family="binomial")

#Prediction

pred <- predict(model,data,type="response")

#Convert to 0/1

pred <- ifelse(pred>0.5,1,0)

#Confusion matrix

table(data$Result,pred)

6. Decision Tree

library(rpart)

data <- [Link]("[Link]")

#Model

model <- rpart(Result~.,data=data,method="class")

#Prediction

pred <- predict(model,data,type="class")

#Confusion matrix

table(data$Result,pred)

7. KNN

library(class)

data <- [Link]("[Link]")

#KNN prediction
pred <- knn(data[,-1],data[,-1],data[,1],k=3)

#Confusion matrix

table(data[,1],pred)

8. ARIMA (Time Series)

data <- [Link]("[Link]")

#Convert to time series

tsdata <- ts(data$Sales)

#ARIMA model

model <- arima(tsdata,order=c(1,1,1))

#Forecast

predict(model,[Link]=5)

9. Naive Bayes

library(e1071)

data <- [Link]("[Link]")

#Model

model <- naiveBayes(Result~.,data=data)

#Prediction

pred <- predict(model,data)

#Confusion matrix

table(data$Result,pred)

One Important Exam Tip

Most R lab programs follow this same pattern:

[Link]()

library() (if needed)

model <- function()

predict()

table() or summary()

Only the model function changes:

Method Function

Linear Regression lm()


Method Function

Multiple Regression lm()

Logistic Regression glm()

Decision Tree rpart()

KNN knn()

Naive Bayes naiveBayes()

ARIMA arima()

You might also like