“Support Vector Machine” (SVM) is a supervised machine learning algorithm. It is used for both classification or regression challenges. But in most of cases it used to solve the classification problems, here we plot each data item as a point in n-dimensional space ( n is number of features).
The goal of the SVM algorithm is to create the best line or decision boundary that can segregate n-dimensional space into classes so that we can easily put the new data point in the correct category in the future. This best decision boundary is called a hyperplane.
Example Using Sklearn:
# importing required librariesimport pandas as pdfrom sklearn.svm import SVCfrom sklearn.metrics import accuracy_score# read the train and test datasettrain_data = pd.read_csv('train-data.csv')test_data = pd.read_csv('test-data.csv')# shape of the datasetprint('Shape of training data :',train_data.shape)print('Shape of testing data :',test_data.shape)# seperate the independent and target variable on training datatrain_x = train_data.drop(columns=['Income'],axis=1)train_y = train_data['Income']# seperate the independent and target variable on testing datax_test = test_data.drop(columns=['Income'],axis=1)y_test = test_data['Income']model = SVC()# fit the model with the training datamodel.fit(x_train,y_train)# predict the target on the train datasetpredict_train = model.predict(x_train)print('Target on train data',predict_train) # Accuray Score on train datasetaccuracy_train = accuracy_score(y_train,predict_train)print('accuracy_score on train dataset : ', accuracy_train)# predict the target on the test datasetpredict_test = model.predict(x_test)print('Target on test data',predict_test) # Accuracy Score on test datasetaccuracy_test = accuracy_score(test_y,predict_test)print('accuracy_score on test dataset : ', accuracy_test)