Skip to content

Instantly share code, notes, and snippets.

@iamjalipo
Last active February 12, 2022 12:21
Show Gist options
  • Save iamjalipo/3d2d7336239b40a66ce473dd2f8222d5 to your computer and use it in GitHub Desktop.
Save iamjalipo/3d2d7336239b40a66ce473dd2f8222d5 to your computer and use it in GitHub Desktop.
svm-03
from sklearn.utils import shuffle
from sklearn.cross_validation import train_test_split
import numpy as np
## Drop rest of the features and extract the target values
df = df.drop(['SepalWidthCm','PetalWidthCm'],axis=1)
Y = []
target = df['Species']
for val in target:
if(val == 'Iris-setosa'):
Y.append(-1)
else:
Y.append(1)
df = df.drop(['Species'],axis=1)
X = df.values.tolist()
## Shuffle and split the data into training and test set
X, Y = shuffle(X,Y)
x_train = []
y_train = []
x_test = []
y_test = []
x_train, x_test, y_train, y_test = train_test_split(X, Y, train_size=0.9)
x_train = np.array(x_train)
y_train = np.array(y_train)
x_test = np.array(x_test)
y_test = np.array(y_test)
y_train = y_train.reshape(90,1)
y_test = y_test.reshape(10,1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment