SVM implementation Issue

I have no idea what you mean by this statement.

Please use

https://dataaspirant.com/wp-content/uploads/2017/01/heart_tidy.csv" to download required dataset

Anything wrong in

split<-createDataPartition(y=heart_dataframe$V14, p=0.7, list=FALSE)

Please help

telling me to download a dataset does not explain your comment about output and 120

Ignore 120

please help for

split<-createDataPartition(y=heart_dataframe$V14, p=0.7, list=FALSE)

Why are you asking this? You believe your data was not partitioned in your previous code?

As previous code did not worked , so now we are trying with

split <- createDataPartition(y=heart_dataframe$V14,p=0.60, list=FALSE)
training_data<-heart_dataframe[split,]
testing_data<-heart_dataframe[-split,]

But issue in split

split <- createDataPartition(y=heart_dataframe$V14, p=0.60, list=FALSE)
Error in createDataPartition(y = heart_dataframe$V14, p = 0.6, list = FALSE) :
y must have at least 2 data points

explain to me in what way or how you know that the previous code did not work.
it seems you have settled on splitting methodologies as your way to address your unstated issue, but I see no justification for this. Until you provide argued reason for changing your approach to splitting, I will not assist you further. It is very frustrating to help a non-communicative partner.

Let us explain us again, our task is

  • Capture the attribute names of the dataset while executing the algorithm.
  • The training dataset should contain 60 percent data from the dataset.
  • The testing dataset should contain the remaining data from the dataset.

Above task we did now by -

split <- createDataPartition(y=heart_dataframe$X63, p=0.60, list=FALSE)
training_data<-heart_dataframe[split,]
testing_data<-heart_dataframe[-split,]

  • Ensure that both the arguments of the confusion matrix are 'factors'.

for this we tried

train_control<-trainControl(method="repeatedcv",number=10,repeats=3)

svm_train<-train(X63 ~.,data=training_data,method="svmLinear",
trControl=train_control,preProcess=c("center","scale"),tuneLength=10)

testing_predictions<-predict(svm_train, newdata=testing_data)

  • Store the result of the confusion matrix in a "cm" variable.

Facing issue here

a<- factor(testing_predictions)
n <- factor(testing_data$X63)
cm <- confusionMatrix(a,n)
Error in confusionMatrix.default(a, n) : the data cannot have more levels than the reference

Thanks complete code which is working is

split <- createDataPartition(y=heart_dataframe$X63, p=0.60, list=FALSE)
training_data<-heart_dataframe[split,]
testing_data<-heart_dataframe[-split,]
train_control<-trainControl(method="repeatedcv",number=10,repeats=3)
svm_train<-train(X63 ~.,data=training_data,method="svmLinear",
trControl=train_control,preProcess=c("center","scale"),tuneLength=10)
testing_predictions<-predict(svm_train, newdata=testing_data)
(avg <- mean(testing_data$X63))
test_data <- factor(x=testing_data$X63>avg)
test_pred <-factor(x=testing_predictions>avg)
(cm<-confusionMatrix(test_pred,test_data))

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.