Skip to content

Instantly share code, notes, and snippets.

@HackerEarthBlog
Last active April 26, 2020 22:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save HackerEarthBlog/07492b3da67a2eb0ee8308da60bf40d9 to your computer and use it in GitHub Desktop.
Save HackerEarthBlog/07492b3da67a2eb0ee8308da60bf40d9 to your computer and use it in GitHub Desktop.
SVM with linear kernel and C=1 for Iris Data
from sklearn import datasets, svm
from sklearn.model_selection import train_test_split
from sklearn.metrics import confusion_matrix
iris = datasets.load_iris()
X = iris.data[:, :2]
y = iris.target
#Split the data into test and train
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)
# Linear Kernel
svc_linear = svm.SVC(kernel='linear', C=1)
svc_linear.fit(X_train, y_train)
predicted= svc_linear.predict(X_test)
cnf_matrix = confusion_matrix(y_test, predicted)
print(cnf_matrix)
# Output
[[16 0 0]
[ 0 13 5]
[ 0 4 7]]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment