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

Bi Pract 9

This document describes performing linear regression on student exam and final score data. It includes steps to import and plot the data, create a training and test split, fit a linear regression model, make predictions on the test data, and calculate accuracy metrics.

Uploaded by

skyverma0709
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)
27 views8 pages

Bi Pract 9

This document describes performing linear regression on student exam and final score data. It includes steps to import and plot the data, create a training and test split, fit a linear regression model, make predictions on the test data, and calculate accuracy metrics.

Uploaded by

skyverma0709
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

Aim: Perform the Linear regression on the given data warehouse data.

#IMPOER DATASET:

Command:

>data=read.csv (“D://tycs/score.csv”)

>data

#PLOT THE DATASET:

COMMAND:

>plot(x=data$Exam1,y=data$Final_score)
#PLOT THE SCATTER DIAGRAM:

>scatter.smooth(x=data$Exam3,y=data$Final_score)
#PARTITIONING THE DATABASE INTO TRAINING AND TESTING SET

s=sample(nrow(data),.7*nrow(data))

score_tr=data[s,]

score_test=data[-s,]

score_tr
#CREATING A MODEL

#PREDICTING THE OUTPUT ON TEST DATASET

❖ Plot Scatter plot


>x=read.csv("D:/TYCS46/score.csv")
>x
Exam1 Exam2 Exam3 Exam4 Final_score Grade
1 60 10 16 7.0 40.79 C
2 90 0 0 0.0 69.23 B
3 130 20 24 1.0 76.75 B
4 130 10 24 8.5 75.66 B
5 90 5 22 9.5 55.48 C
.
.
.
.
.
.
> s=sample(nrow(x),.7*nrow(x))
>score_tr=x[s,]
>score_test=x[-s,]
>scatter.smooth(x=score_tr$Exam3,y=score_tr$Final_score)
❖ Get Linear regression
>linmod=lm(Final_score~Exam3,data=score_tr)
>print(linmod)

Call:
lm(formula = Final_score ~ Exam3, data = score_tr)

Coefficients:
(Intercept) Exam3
35.90 1.32
❖ Prediction
> p=predict(linmod,score_test)
>actuals_preds = data.frame(cbind(actuals=score_test$Final_score,predicts=p))
>actuals_preds
actuals predicts
2 69.23 35.89681
11 68.86 62.30306
14 60.00 59.66244
15 60.00 59.66244
16 60.11 67.58432
26 83.99 75.50619
27 73.25 67.58432
32 90.79 67.58432
35 88.38 49.09994
39 51.25 57.02181
41 29.61 49.09994
44 65.13 54.38119
47 78.10 67.58432
50 94.08 72.86557
54 53.33 57.02181
56 51.97 72.86557
57 87.50 75.50619
62 11.11 35.89681
64 86.18 75.50619
70 45.83 54.38119
71 11.11 35.89681
78 64.29 62.30306
79 59.65 54.38119
84 74.34 67.58432
85 5.56 35.89681
88 47.50 59.66244
90 67.50 67.58432
91 71.49 67.58432
93 60.31 62.30306
94 63.78 62.30306
96 73.81 62.30306
99 18.86 72.86557

❖ Print Accuracy
> min_max_accuracy=mean(apply(actuals_preds,1,min)/apply(actuals_preds,1,max))
>min_max_accuracy
[1] 0.7806829
>mape=mean(abs((actuals_preds$predicteds-actuals_preds$actuals))/actuals_preds$actuals)
>mape
[1] 0.68783456

Conclusion:

You might also like