1

Im having an error bad input shape I tried searching but I can't understand yet since im new in SVM.

train.csv
testing.csv

# importing required libraries
import numpy as np

# import support vector classifier
from sklearn.svm import SVC 
import warnings
warnings.simplefilter(action='ignore', category=FutureWarning)


X = pd.read_csv("train.csv")
y = pd.read_csv("testing.csv")

clf = SVC()
clf.fit(X, y)
clf.decision_function(X)
print(clf.predict(X))



raise ValueError("bad input shape {0}".format(shape))
ValueError: bad input shape (1, 6)

1 Answers1

0

The problem here is that you are just inserting your entire table with the training data (plus labels) as the input for just the training data and then try to predict the table of the testing data (data and labels) with the SVM.

This does not work that way.

What you need to do, is to train the SVM with your training data (so data points + label for each data point) and then test it against your testing data (testing data points + labels).

Your code should look like this instead:

# Load training and testing dataset from .csv files
training_dataset = pd.read_csv("train.csv")
testing_dataset = pd.read_csv("testing.csv")

# Load training data points with all relevant features
X_train = training_dataset[['feature1','feature2','feature3','feature4']]

# Load training labels from dataset
y_train = training_dataset['label']

# Load testing data points with all relevant features
X_test = testing_dataset[['feature1','feature2','feature3','feature4']]

# Load testing labels from dataset
y_test = testing_dataset['label']


clf = SVC()

# Train the SVC with the training data (data points and labels)
clf.fit(X_train, y_train)

# Evaluate the decision function with test samples
clf.decision_function(X_test)

# Predict the test samples
print(clf.predict(X_test))

I hope that helps and that this code runs for you. Let me know if I misunderstood something or you have more questions. :)

Kim Tang
  • 2,330
  • 2
  • 9
  • 34