Skip to content

Commit

Permalink
linear svm
Browse files Browse the repository at this point in the history
  • Loading branch information
spmallick committed Jul 27, 2018
1 parent f62a16c commit e525963
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions SVM-using-Python/Linear-Data-Without-Noise/svm-classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,30 @@

sys.path.append(os.path.abspath("../"))
from utils import read_data, plot_data, plot_decision_function

# Read data
x, labels = read_data("points_class_0.txt", "points_class_1.txt")

# Split data to train and test on 80-20 ratio
X_train, X_test, y_train, y_test = train_test_split(x, labels, test_size = 0.2, random_state=0)

print("Displaying data. Close window to continue.")
# Plot traning and test data
plot_data(X_train, y_train, X_test, y_test)



print('Training Linear SVM')
# Create a linear SVM classifier
clf = svm.SVC(C = 1.0, kernel='linear')
clf = svm.SVC(kernel='linear')

# Train classifier
clf.fit(X_train, y_train)

# Make predictions on unseen test data
clf_predictions = clf.predict(X_test)

print("Displaying decision function. Close window to continue.")
# Plot decision function on training and test data
plot_decision_function(X_train, y_train, X_test, y_test, clf)

# Make predictions on unseen test data
clf_predictions = clf.predict(X_test)
print("Accuracy: {}%".format(clf.score(X_test, y_test) * 100 ))

0 comments on commit e525963

Please sign in to comment.