Last active
May 23, 2016 16:24
-
-
Save matmoody/7279daee48740ef9e29688193445a9c3 to your computer and use it in GitHub Desktop.
Linear SVC on iris data set
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
import pandas as pd | |
import numpy as np | |
# Read in iris data set | |
iris = pd.read_csv("https://raw.githubusercontent.com/Thinkful-Ed/curric-data-001-data-sets/master/iris/iris.data.csv") | |
# Add column names | |
iris.columns = ['SepalLengthCm', 'SepalWidthCm', 'PetalLengthCm', 'PetalWidthCm', 'Species'] | |
# Split data into features and target | |
X = iris.ix[:, 0:4] | |
y = iris.ix[:, 4:] | |
# Train, test split | |
X_train, X_test, y_train, y_test = train_test_split(columns, y, test_size=0.40, random_state=42) | |
from sklearn.svm import LinearSVC | |
# Build Linear Support Vector Classifier | |
clf = LinearSVC() | |
clf.fit(X_train, y_train) | |
# Make predictions on test set | |
predictions = svc.predict(X_test) | |
from sklearn.metrics import accuracy_score | |
# Assess model accuracy | |
result = accuracy_score(y_test, predictions, normalize=True) | |
print result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment