Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 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

Institution
Module

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)

Written for

Institution
Study
Module

Document information

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

Subjects

$4.81
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

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
Follow You need to be logged in order to follow users or courses
Sold
64
Member since
4 year
Number of followers
34
Documents
29
Last sold
3 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

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

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions