0% found this document useful (0 votes)
19 views8 pages

DTE-2 R Language Paper

The document contains a series of code snippets and outputs for different statistical models including Simple Linear Regression, Support Vector Machine (SVM), and Artificial Neural Network (ANN). It demonstrates data loading, model training, predictions, and evaluation metrics such as accuracy. The results indicate varying levels of accuracy for the models applied to different datasets.

Uploaded by

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

DTE-2 R Language Paper

The document contains a series of code snippets and outputs for different statistical models including Simple Linear Regression, Support Vector Machine (SVM), and Artificial Neural Network (ANN). It demonstrates data loading, model training, predictions, and evaluation metrics such as accuracy. The results indicate varying levels of accuracy for the models applied to different datasets.

Uploaded by

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

Name – Sanskruti Nimje

Reg. no. – 2023PGDM1233

Section – B

DTE-2

SECTION-A

Q-1) Simple Liner Regression

syntax

#simple liner regression

salary_data=read.csv("D:\\salary_data.csv")

View(salary_data)

attach(salary_data)

#model

model=lm(Salary~Years.of.Experience,data=salary_data)

names(salary_data)

summary(model)

prediction=predict(model,data.frame(Years.of.Experience=5))

prediction

output

#simple liner regression

> salary_data=read.csv("D:\\salary_data.csv")

> View(salary_data)

> attach(salary_data)

The following objects are masked from salary_data (pos = 3):


Age, Education.Level, Gender, Salary, Years.of.Experience

The following objects are masked from salary_data (pos = 4):

Age, Education.Level, Gender, Salary, Years.of.Experience

The following objects are masked from salary_data (pos = 5):

Age, Education.Level, Gender, Salary, Years.of.Experience

The following objects are masked from salary_data (pos = 6):

Age, Education.Level, Gender, Salary, Years.of.Experience

> #model

> model=lm(Salary~Years.of.Experience,data=salary_data)

> names(salary_data)

[1] "Age" "Gender" "Education.Level" "Years.of.Experience"

[5] "Salary"

> summary(model)

Call:

lm(formula = Salary ~ Years.of.Experience, data = salary_data)

Residuals:

Min 1Q Median 3Q Max

-69589 -7188 1189 9634 78567

Coefficients:

Estimate Std. Error t value Pr(>|t|)


(Intercept) 31921.2 1677.8 19.02 <2e-16 ***

Years.of.Experience 6844.5 140.1 48.87 <2e-16 ***

---

Signif. codes: 0 ‘’ 0.001 ‘’ 0.01 ‘’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 17710 on 371 degrees of freedom

(2 observations deleted due to missingness)

Multiple R-squared: 0.8655, Adjusted R-squared: 0.8652

F-statistic: 2388 on 1 and 371 DF, p-value: < 2.2e-16

> prediction=predict(model,data.frame(Years.of.Experience=5))

> prediction

66143.77

>

>

………………………………………………………………………………………………………………….

SECTION-B

Q-4)

# SVM MODEL

data=read.csv("C://Users/HP/Desktop/DATA DAR/heart.csv")

View(data)

index=sample(2,nrow(data),replace = TRUE,prob = c(0.9,0.1))


train_data=data[index==1,]

test_data=data[index==2,]

install.packages('e1071')

library(e1071)

model=svm(target~.,train_data,kernel = "linear",type = "C-classification")

prediction_class=predict(model,test_data)

prediction_class

matrix=table(test_data$target,prediction_class)

matrix

accuracy=(sum(diag(matrix))/sum(matrix))

accuracy

OUTPUT

data=read.csv("D:\\heart.csv")
> View(data)
> index=sample(2,nrow(data),replace = TRUE,prob = c(0.8,0.2))
> train_data=data[index==1,]
> test_data=data[index==2,]
> library(e1071)
model=svm(target~.,train_data,kernel = "linear",type = "C-classification")
> prediction_class=predict(model,test_data)
> prediction_class
1 8 11 17 21 28 31 36 40 46 50 51 54 59 68 72 77 89 99
0 0 1 1 1 1 0 0 1 1 0 1 0 1 0 0 1 0 1
111 112 113 115 118 119 123 129 136 156 161 162 163 164 178 180 188 201 204
1 0 0 1 0 1 0 1 0 1 0 1 0 0 0 0 0 1 1
210 211 237 241 256 257 266 271 272 277 280 281 290 292 299 305 310 318 322
0 1 1 1 1 1 0 1 1 0 1 1 1 0 1 1 1 1 1
323 329 330 334 335 336 341 343 344 353 360 368 381 384 389 391 399 405 418
0 0 1 1 0 0 1 1 1 0 1 1 0 0 0 1 0 0 1
421 427 447 454 467 469 472 485 486 488 490 491 494 496 499 504 508 513 519
1 1 1 1 1 1 1 1 0 0 1 1 0 0 1 1 1 1 0
520 533 536 537 539 541 549 551 558 559 565 566 573 579 581 587 588 589 594
0 1 1 1 0 0 1 0 1 1 0 1 1 1 1 0 0 0 0
597 602 603 605 606 610 614 620 622 623 632 647 666 671 675 685 688 694 700
1 0 1 1 1 0 0 1 0 0 1 1 1 1 0 1 0 1 0
706 710 711 716 722 728 739 750 762 764 781 795 802 814 823 826 833 834 842
0 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 1 0 1
846 847 851 853 854 876 880 886 890 892 916 919 932 936 945 948 951 958 960
0 1 1 0 0 0 1 0 0 1 0 1 1 1 0 1 0 1 1
961 963 964 965 966 969 981 983 988 990 996 1000 1001 1004 1010 1014
1 0 0 1 1 0 1 1 1 1 1 0 0 0 1 0
Levels: 0 1
> matrix=table(test_data$target,prediction_class)
> matrix
prediction_class
0 1
0 71 26
1 8 82
> accuracy=(sum(diag(matrix))/sum(matrix))
> accuracy
[1] 0.8181818
>

…………………………………………………………………………………………………………………………..

SECTION -C

Q-5) CASE STUDY

syntax

#ANN MODEL

install.packages('neuralnet')

library(neuralnet)

binary_data<-read.csv("D:\\dividendinfo.csv")

View(binary_data)

index<-sample(2,nrow(binary_data), replace = TRUE, prob = c(0.9,0.1))

train_data<-binary_data[index==1,]

test_data<-binary_data[index==2,]
ann_model<-neuralnet(dividend~.,train_data,hidden = 1,err.fct = 'ce',linear.output = FALSE)

plot(ann_model)

prediction<-compute(ann_model,test_data[,-9])

result<-prediction$net.result

pred_class<-ifelse(result>0.5,1,0)

pred_class

matrix<-table(test_data$dividend,pred_class)

matrix

accuracy<-(sum(diag(matrix))/sum(matrix))

accuracy

output

library(neuralnet)

> binary_data<-read.csv("D:\\dividendinfo.csv")

> View(binary_data)

> index<-sample(2,nrow(binary_data), replace = TRUE, prob = c(0.9,0.1))

> train_data<-binary_data[index==1,]

> test_data<-binary_data[index==2,]

> ann_model<-neuralnet(dividend~.,train_data,hidden = 1,err.fct = 'ce',linear.output = FALSE)

> plot(ann_model)

prediction<-compute(ann_model,test_data[,-9])

> result<-prediction$net.result

> pred_class<-ifelse(result>0.5,1,0)

> pred_class

[,1]

8 1

10 1

18 1
41 1

69 1

81 1

87 1

112 1

121 1

127 1

132 1

137 1

153 1

161 1

183 1

186 1

194 1

> matrix<-table(test_data$Outcome,pred_class)

Error in table(test_data$Outcome, pred_class) :

all arguments must have the same length

> matrix<-table(test_data$dividend,pred_class)

> matrix

pred_class

09

18

> accuracy<-(sum(diag(matrix))/sum(matrix))

> accuracy

[1] 0.5294118

>
……………………………………………………………………………………………………………………………………………………………

You might also like