# SVM with multiple features

import numpy as np
import matplotlib.pyplot as plt
from matplotlib import style
style.use("ggplot")
from sklearn import svm

X=[[1,0,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[1,0,0,1,0],
[1,0,0,0,1]]

y=[0,1,1,1,0]

model=svm.SVC()
model.fit(X,y)
print(model.predict([1,0,1,0,0]))


I was working on this but Iam getting an error as

"if it contains a single sample.".format(array))
ValueError: Expected 2D array, got 1D array instead:
array=[1. 0. 1. 0. 0.].
Reshape your data either using array.reshape(-1, 1) if your data has a single fe
ature or array.reshape(1, -1) if it contains a single sample.


Iam new to this can u guys help me out?

After having performed

X=np.array([[1,0,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[1,0,0,1,0],
[1,0,0,0,1]])

y=np.array([0,1,1,1,0])


you have to do the following:

y = y.reshape(1, -1)

model=svm.SVC()
model.fit(X,y)
test = np.array([1,0,1,0,0])
test = test.reshape(1,-1)
print(model.predict(test))


In future you have to scale your dataset. You can use either Standard Scaler (suggested) or MinMax Scaler.

• I guess print(model.predict([1,0,1,0,0])) should be print(model.predict(np.array([[1,0,1,0,0]]))), maybe :) Idon't have possibility to check right now – Media Apr 12 '18 at 16:11
• did you run it? – Media Apr 12 '18 at 16:27

Your inputs are lists but they need to be arrays.

X=np.array([[1,0,0,0,0],
[0,1,0,0,0],
[0,0,1,0,0],
[1,0,0,1,0],
[1,0,0,0,1]])

y=np.array([0,1,1,1,0])