DTE-2 R Language Paper
DTE-2 R Language Paper
Section – B
DTE-2
SECTION-A
syntax
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
> 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)
[5] "Salary"
> summary(model)
Call:
Residuals:
Coefficients:
---
> 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)
test_data=data[index==2,]
install.packages('e1071')
library(e1071)
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
syntax
#ANN MODEL
install.packages('neuralnet')
library(neuralnet)
binary_data<-read.csv("D:\\dividendinfo.csv")
View(binary_data)
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)
> train_data<-binary_data[index==1,]
> test_data<-binary_data[index==2,]
> 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)
> matrix<-table(test_data$dividend,pred_class)
> matrix
pred_class
09
18
> accuracy<-(sum(diag(matrix))/sum(matrix))
> accuracy
[1] 0.5294118
>
……………………………………………………………………………………………………………………………………………………………