Last active
April 26, 2020 22:12
-
-
Save HackerEarthBlog/07492b3da67a2eb0ee8308da60bf40d9 to your computer and use it in GitHub Desktop.
SVM with linear kernel and C=1 for Iris Data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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