import codecademylib3_seaborn
import matplotlib.pyplot as plt
from sklearn.svm import SVC
from sklearn.model_selection import train_test_split
from svm_visualization import draw_boundary
from players import aaron_judge, jose_altuve, david_ortiz

fig, ax = plt.subplots()
aaron_judge.type = aaron_judge.type.map({'S':1,'B':0})
aaron_judge = aaron_judge.dropna(subset = ['type','plot_x','plot_z'])

print(aaron_judge.plot_z)
plt.scatter(x = aaron_judge.plot_x,y = aaron_judge.plt_z,c= aaron_judge.type,cnap = plt.cn.coolwarm,
alpha =0.25)
training_set ,validation_set = train_test_split(aaron_judge,random_state=1)
largest = {'value':0,'gamma':1,'C':1}
for gamma in range(1,20):
  for C in range(1,20):
    classifier = SVC(kernel = 'rbf',gamma= gamma,C)
    classifier.fit(training_set[['plot_x','plot_z']]
    training_set.type)
    score = classifier.score(
      validation_set[['plot_x','plot_z']],validation_set.type)
  if(score>largest['value']):
    largest['value']-score
    largest['gamma'] = gamma
    largest['C'] = C 
  


print(largest)
draw_boundary(ax,classifier)
plt.show()
