I am working on Part 2 and I believe I have things built
correctly in r but can't figure out how to compare the predictions
and build the confusion matrix asked for. I'm posting my
code below:
> x=read.table("hw05dataTrain.txt", header=TRUE)
> y=read.table("hw05dataTest.txt", header=TRUE)
> ind0=x[,3]==0
> ind1=x[,3]==1
> ind2=x[,3]==2
> x01=x[ind0 | ind1,]
> ind=x01[,3]==0
> x01[ind, 3]=1
> x01[!ind, 3]=-1
> x01[,3]=as.factor(x01[,3])
> mod01=svm(x01[,1:2],x01[,3])
> pred=predict(mod01,y[,1:2])
>
> x02=x[ind0 | ind2,]
> ind=x02[,3]==0
> x02[ind, 3]=1
> x02[!ind, 3]=-1
> x02[,3]=as.factor(x02[,3])
> mod02=svm(x02[,1:2],x02[,3])
> pred02=predict(mod02, y[,1:2])
>
> x12=x[ind1 | ind2,]
> ind=x12[,3]==1
> x12[ind, 3]=1
> x12[!ind, 3]=-1
> x12[,3]=as.factor(x12[,3])
> mod12=svm(x12[,1:2],x12[,3])
> pred12=predict(mod12,y[,1:2])
CIS 635 Data Mining Homework 5 Description This homework has you practicing some of the practical concepts related to SVM. Instructions X1 X2 3.8 Part 1 - predicting In this first part, you are given the vector w that determines the Xv linear decision boundary for a particular data training set. You 1 2.1 are lo assume that SVM has beco uscd on the data sct lo lind w. 1 9.7 Your task is to make predictions on new data, given w. The new 7.2 data instances are in the table to the right and w={-4, 1, -2}, Predict the class of the new instances (1, -1 or 0). The class is 1 if x.w> 1, and -1 if x.w<-1. If it is between -1 and 1, the class is indeterminate (i.e. O). 1.3 1 1.3 Part 2 - using SVM for a problem with 3 class values Using the training data hw06dataTrain.txt and test data hwO6dataTest.txt for this exercise. The training and test sets both have 2 numeric attributes and a nominal class. The class can be one of three values 0, 1 and 2. It may be helpful for you to plot the data in a scatter plot. You are to use SVM to classify the test records. Since it is a binary classifier you cannot just create a single model. The approach you will take is pairwise. You will create three models. First you will create a now training sct with just the instances that are class 0 and class 1 (in the acw sets modify the class values so they are 1 and -1). Use SVM to train a model (use the default kernel, which is radial) on this set (I will refer to this as mod01). Then create another training set with just the class 0 and 2 (again, change the classes to 1 and -1). Train another model on this set (modo2). Finally train another model (mod12) on a set with classes 1 and 2. It is very important that you are organized; think clearly about which model is predicting which class. After you have the three models trained you can use them to predict the test set. Use the majority rule to assign class. That is, if mod01 predicts and modo2 predicts 2 and mod12 predicts 2, then assign it class 2. In the unlikely case where the three models predict three different classes, assigo it a class of 0. When you are finished print the confusion matrix and a script of the R commands that you used.
I am working on Part 2 and I believe I have things built correctly in r but can't figure out how to compare the predicti
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am