SCRIPT FOR DATA SET 2 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/a2trainx2",
+ head=TRUE)
> train_y <- scan ("http://www.cs.utoronto.ca/~radford/csc120/a2trainy2",
+ character())
Read the inputs for test cases.
> test_x <- read.table ("http://www.cs.utoronto.ca/~radford/csc120/a2testx2",
+ head=TRUE)
Classify the test cases with the original inputs, putting the guessed classes in 'cl'.
> cl <- classify (train_x, train_y, test_x)
Classify the test cases using rescaled inputs, putting the guessed classes in 'cl_rescaled'.
> rescale <- function (datax)
+ {
+ datax$age <- datax$age / 10
+ datax$BP <- datax$BP / 100
+ datax$chol <- datax$chol / 100
+ datax$rate <- datax$rate / 100
+
+ datax
+ }
>
> cl_rescaled <- classify (rescale(train_x), train_y, rescale(test_x))
Read the actual classes for the test cases.
> test_y <- scan ("http://www.cs.utoronto.ca/~radford/csc120/a2testy2",
+ character())
Print the classification accuracy with the original inputs and the rescaled inputs.
> cat ("Classification accuracy with original inputs:",
+ mean (cl == test_y), "\n")
Classification accuracy with original inputs: 0.625
> cat ("Classification accuracy with rescaled inputs:",
+ mean (cl_rescaled == test_y), "\n")
Classification accuracy with rescaled inputs: 0.7416667