Last active
April 6, 2022 00:56
-
-
Save sithu/bf18f4def8f7ab80bfdfc2ac7fe26985 to your computer and use it in GitHub Desktop.
This file contains 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
import pandas as pd | |
import numpy as np | |
import matplotlib.pyplot as plt | |
# https://gist.github.com/sithu/4722649d23c83440f2067ed429fa434b | |
import utils | |
from sklearn.svm import SVC | |
# Loading the linear dataset | |
# linear.csv: https://gist.github.com/sithu/701d1182d63b01e740bb244d8059ceb1 | |
linear_data = pd.read_csv('linear.csv') | |
features = np.array(linear_data[['x_1', 'x_2']]) | |
labels = np.array(linear_data['y']) | |
utils.plot_points(features, labels) | |
# Find accuracy | |
svm_linear = SVC(kernel='linear') | |
svm_linear.fit(features, labels) | |
print("Accuracy:", svm_linear.score(features, labels)) | |
utils.plot_model(features, labels, svm_linear) | |
# Set C - hyperparameter | |
# C = 0.01 and C = 100: Which C gives better accuracy? | |
svm_c_001 = SVC(kernel='linear', C=0.01) | |
svm_c_001.fit(features, labels) | |
print("C = 0.01") | |
print("Accuracy:", svm_c_001.score(features, labels)) | |
utils.plot_model(features, labels, svm_c_001) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment