I have a huge dataframe that I want to run a multi class svm model on but I am confused on how to format the dataframe to do so. This is what the dataframe looks like:
| x | y | class |
|---|---|---|
| x1 | y1 | 1 |
| x2 | y2 | 2 |
| x3 | y3 | 3 |
| x4 | y4 | 4 |
| etc | etc | etc |
How do I actually run the data on an svm model? thanks
CodePudding user response:
Simply do this
X=df[['x','y']]
Y=df[['class']]
After this you will have columns x and y in X and column 'class' in Y you may split data further into X_train, X_test, Y_train, Y_test by using split function in sklearn library and you the implement SVM using the library of your choice and do the follow up procedures.
Refer to this link for more information on implementing SVM
CodePudding user response:
import pandas as pd
from sklearn import svm
df=pd.read_excel('Enter location of your dataset')
features=df[['x','y']]
classes=df[['class']]
clf = svm.SVC(features,classes)
clf.fit(X, y)
