SCRIPT FOR DATA SET 1 FOR CSC 120 ASSIGNMENT 2.

Read the function defintions.

> source("http://www.cs.utoronto.ca/~radford/csc120/a2funs.r")

Read the inputs and classes for the training cases.

> train_x <- read.table ("http://www.cs.utoronto.ca/~radford/csc120/a2trainx1",
+                         head=TRUE)
> train_y <- scan ("http://www.cs.utoronto.ca/~radford/csc120/a2trainy1")

Plot the training data, with variables x1 and x2 for horizontal and vertical coordinates, variable x3 for plot symbol, and class for colour (0=green, 1=red).

> plot (train_x$x1, train_x$x2, pch=as.character(train_x$x3), 
+                               col=c("green","red")[train_y+1])

plot of chunk unnamed-chunk-4

Read the inputs for test cases.

> test_x <- read.table ("http://www.cs.utoronto.ca/~radford/csc120/a2testx1", 
+                        head=TRUE)

Classify the test cases, putting the guessed classes in 'cl'.

> cl <- classify (train_x, train_y, test_x)

Read the actual classes for the test cases.

> test_y <- scan("http://www.cs.utoronto.ca/~radford/csc120/a2testy1")

Print the guesses for the test classes and the actual classes, and the classification accuracy.

> print(cl)
 [1] 1 1 1 0 0 1 1 1 1 0 0 1 1 0 1 0 0 0 0 1 0 0 1 0 1 0 1 0 1 0
> print(test_y)
 [1] 0 0 1 1 1 1 1 1 1 0 1 1 1 0 1 0 0 0 0 1 0 0 1 0 1 1 1 0 1 0
> cat ("Classification accuracy:", mean (cl == test_y), "\n")
Classification accuracy: 0.8