Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
itsdebartha authored Jul 4, 2021
1 parent a9c3156 commit b270897
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions Task-1.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#Install the 'Metrics' package if you do not have that installed

#Loading the required libraries
library(Metrics)

#Reading the dataset
s_data<-read.csv('http://bit.ly/w-data',header=T)

#Dimensions of the dataset
dim(s_data)

#A glimpse of the dataset
head(s_data,n=5)

#Column names of the dataset
names(s_data)

#Plotting the dataset to get a clear view of the dataset
par(bg='#CCFFFF')
plot(s_data$Hours,s_data$Scores,pch=16,col='dark blue',
xlab='Hours studied',ylab='Precentage Score',
main='Hours vs. Percentage')
legend(x=1,y=95,'Scores',pch=16,col='dark blue')

#Seperate the train and test data
X<-s_data$Hours;Y<-s_data$Scores
t_sample<-sample(nrow(s_data),floor(0.8*nrow(s_data)),replace=F)
X_train<-X[t_sample];Y_train<-Y[t_sample]
X_test<-X[-t_sample];Y_test<-Y[-t_sample]

#Fit a linear model
model<-lm(Y_train~X_train)
par(bg='#CCFFCC')
plot(s_data$Hours,s_data$Scores,pch=16,col='dark blue',
xlab='Hours studied',ylab='Precentage Score',
main='Hours vs. Percentage')
abline(model,col='red',lwd=2)

#Predictions
X_test#Testing data
Y_predicted<-predict(model,newdata=data.frame(X_train=X_test))#Predicting the scores
df<-data.frame('Hours'=X_test,'Actual score'=Y_test,'Predicted score'=Y_predicted)
df
pred<-predict(model,newdata=data.frame(X_train=9.25))
pr_data<-data.frame('Hours'=9.25,'Predicted Score'=pred)
pr_data

#Accuracy
mae(df$Actual,df$Predicted)

0 comments on commit b270897

Please sign in to comment.