100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

Brunel - Computer Science - CS3002 Artificial Intelligence R Studio Scripts (ALL LABS Complete)

Rating
-
Sold
1
Pages
4
Grade
A+
Uploaded on
28-02-2022
Written in
2020/2021

Compilation of the labs Intro to R, Classification, Clustering, Neural Networks Labs Scripts. CS3002 Artificial Intelligence Labs at Brunel University Cannot attach the data - message on here and I can do that for you









Whoops! We can’t load your doc right now. Try again or contact support.

Document information

Uploaded on
February 28, 2022
Number of pages
4
Written in
2020/2021
Type
Exam (elaborations)
Contains
Questions & answers

Content preview

#LAB1 Intro to R _______________________________
mydata = read.csv('', sep=",")

meantemp = mean(mydata$temp)
plot(mydata$temp,mydata$ISI)
lmfire=line(mydata$ISI~mydata$temp)
abline(coef(lmfire))

#LAB2 Classification _______________________________
#read in csv files & preparing dataset
iris = read.csv('C:\\iris.csv', sep=",")
colnames(iris) <- c("sepal","petal","width", "length")
iris_real = read.csv('C:\\iris_real.csv', sep=",")
iris <- rbind(c(5.1, 3.5, 1.4, 0.2), iris)
iris_real <- rbind(c(1), iris_real)
colnames(iris_real) <- c("Class")
iris <- cbind(iris,iris_real)
iris_rand=iris[sample(150,150),]

irisclass = iris_rand[5]
irisvalues = iris_rand[-5]

#setting up a training set
library(rpart)
irisclassTrain = irisclass[1:100,]
irisvaluesTrain = irisvalues[1:100,]

#testset
irisclassTest = irisclass[100:150,]
irisvaluesTest = irisvalues[100:150,]


#decision trees
fit <- rpart(irisclassTrain~., method="class",data=irisvaluesTrain)
pfit<- prune(fit, cp=0.4)
plot(pfit, uniform=TRUE, main ="Decision Tree for iris data")
text(pfit, use.n=TRUE, all=TRUE, cex=1)

#decision trees different degrees
fit <- rpart(irisclassTrain~., method="class",data=irisvaluesTrain)
pfit<- prune(fit, cp=0.5)
plot(pfit, uniform=TRUE, main ="Decision Tree for iris data")
text(pfit, use.n=TRUE, all=TRUE, cex=1)

#test the classifer on the test set by calculating the predictions for each
testcase in our testset
treepred <- predict(pfit, irisvaluesTest, type = 'class')
n=length(irisclassTest) # the number of test cases
ncorrect = sum(treepred==irisclassTest) #number of correctly predicted
accuracy = ncorrect/n
print(accuracy)

#2 selected variables
plot(irisvaluesTest$width,irisvaluesTest$length, col = treepred)

# K-nearest neighbour
library(class)
#generate our predicted classes
knn3pred = knn(irisvaluesTrain, irisvaluesTest, irisclassTrain, k=3)

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
cslbrunel Brunel University
View profile
Follow You need to be logged in order to follow users or courses
Sold
63
Member since
3 year
Number of followers
34
Documents
29
Last sold
4 months ago
Brunel Computer Science (1st Class Honours)

I achieved a First Class Honours degree in Computer Science from Brunel University - I will be uploading some of my work. Please do not purchase any documents looking for the solution to your assignments or deliverables. No refunds / exchanges.

5.0

2 reviews

5
2
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Frequently asked questions