import pandas as pd
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from sklearn import metrics
iris=load_iris()

#print dir(iris)
#print iris.feature_names

df=pd.DataFrame(iris.data,columns=iris.feature_names)
 

df['target']=iris.target


#print iris.target_names

df['flower_name']=df.target.apply(lambda x: iris.target_names[x] )
#print df.head()
df0=df[df.target==0]
df1=df[df.target==1]
df2=df[df.target==2]

plt.scatter(df0['sepal length (cm)'],df0['sepal width (cm)'],color='green',marker='+')
plt.scatter(df1['sepal length (cm)'],df1['sepal width (cm)'],color='blue',marker='.')
plt.xlabel('Sepal Length')
plt.ylabel('Sepal Width')
#plt.show()

X=df.drop(['target','flower_name'],axis='columns')
#print X.head()

y=df.target
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2)

svm=SVC(kernel='linear')
svm.fit(X_train,y_train)
y_pred=svm.predict(X_test)
print metrics.accuracy_score(y_test,y_pred)
