[SOLVED] Q2_solution

$25

File Name: Q2_solution.zip
File Size: 103.62 KB

5/5 - (1 vote)

Q2_solution

Copyright By Assignmentchef assignmentchef

# Wk11 Task 2. SVM classifier and confusion matrix

import sys
import string

if __name__ == __main__:
from sklearn import svm
from sklearn.metrics import confusion_matrix

X_train=[[0, 0, 0, 0, 2], [3, 0, 1, 0, 1], [0, 0, 0, 0, 1], [2, 0, 3, 0, 2], [5, 2, 0, 0, 1], [0, 0, 1, 0, 1], [0, 1, 1, 0, 1], [0, 0, 0, 0, 1], [0, 0, 0, 0, 1], [1, 1, 0, 1, 2]]
y_train=[-1, 1, -1, 1, 1, -1, -1, -1, -1, -1]

X_test=[[1, 1, 1, 1, 2], [3, 0, 2, 0, 3], [0, 0, 0, 0, 0], [6, 0, 5, 0, 1], [4, 2, 0, 2, 1], [0, 0, 1, 1, 1], [0, 1, 0, 0, 1], [1, 0, 0, 0, 1], [0, 1, 0, 0, 1], [1, 1, 0, 1, 2]]
y_test=[-1, 1, 1, 1, 1, -1, -1, -1, -1, -1]

clf = svm.SVC(gamma=scale)
clf.fit(X_train, y_train)
result1 = clf.predict(X_test)
print(SVC Predication Results: + str(result1))
supp_v = clf.support_vectors_
print(Support Vectors: + str(supp_v))

lin_clf = svm.LinearSVC()
fit=lin_clf.fit(X_train, y_train)
result2 = fit.predict(X_test)
print(Linear Predication Results: s + str(result2))
dec = lin_clf.decision_function(X_test)
print(Linear decision function values: + str(dec))

print(The Confusion Matrix for Result1::)
print(confusion_matrix(y_test, result1))

print(The Confusion Matrix for Result2::)
print(confusion_matrix(y_test, result2))

SVC Predication Results: [-11 -111 -1 -1 -1 -1 -1]
Support Vectors: [[0. 0. 0. 0. 2.]
[0. 0. 1. 0. 1.]
[0. 1. 1. 0. 1.]
[1. 1. 0. 1. 2.]
[3. 0. 1. 0. 1.]
[2. 0. 3. 0. 2.]
[5. 2. 0. 0. 1.]]
Linear Predication Results: s[-11 -111 -1 -1 -1 -1 -1]
Linear decision function values: [-0.682890580.83908391 -0.632860294.311894131.01606936 -0.7565212
-1.20341656 -0.33193098 -1.20341656 -0.96746872]
The Confusion Matrix for Result1::
The Confusion Matrix for Result2::

CS: assignmentchef QQ: 1823890830 Email: [email protected]

Reviews

There are no reviews yet.

Only logged in customers who have purchased this product may leave a review.

Shopping Cart
[SOLVED] Q2_solution
$25