100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Brunel - Computer Science - CS3002 Artificial Intelligence R Studio Scripts (ALL LABS Complete) £2.99   Add to cart

Exam (elaborations)

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

 39 views  1 purchase

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

Preview 1 out of 4  pages

  • February 28, 2022
  • 4
  • 2020/2021
  • Exam (elaborations)
  • Questions & answers
All documents for this subject (11)
avatar-seller
cslbrunel
#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)

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller cslbrunel. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £2.99. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

64438 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 14 years now

Start selling
£2.99  1x  sold
  • (0)
  Add to cart