Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
tywang89 authored Jul 7, 2018
1 parent ba6ae38 commit a1e41be
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 0 deletions.
16 changes: 16 additions & 0 deletions 16 code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pandas as pd
import numpy as np
import statsmodels.api as sm

rawstat = pd.read_table('/Users/wangtianyi/Documents/python_work/poisson regression.csv')
offensive = rawstat.iloc[:,[0,1,2,3,4,5]]
goal = rawstat.iloc[:,6]

offensive_add = sm.add_constant(offensive)
poisson_result = sm.GLM(goal, offensive_add, family=sm.families.Poisson()).fit()
print(poisson_result.summary())

offensive_reduced = offensive.iloc[:,[1,2,5]]
offensive_add = sm.add_constant(offensive_reduced)
poisson_result = sm.GLM(goal, offensive_add, family=sm.families.Poisson()).fit()
print(poisson_result.summary())
33 changes: 33 additions & 0 deletions 17 code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pandas as pd
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from sklearn import svm

ratio = []

rawstat = pd.read_table('/Users/wangtianyi/Documents/python_work/linear inseparable.csv')
category = rawstat.iloc[:,0]
pass_ratio = rawstat.iloc[:,1] / rawstat.iloc[:,2]
shot_ratio = rawstat.iloc[:,3] / rawstat.iloc[:,4]

ratio.append(pass_ratio)
ratio.append(shot_ratio)
ratio = np.array(ratio)
ratio = ratio.astype('float')

linear_svm = svm.SVC(kernel='linear', C=1e10).fit(ratio.T, category)

x_min, x_max = ratio[0].min() - 0.05, ratio[0].max() + 0.05
y_min, y_max = ratio[1].min() - 0.05, ratio[1].max() + 0.05
xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.01), np.arange(y_min, y_max, 0.01))
xy = np.vstack([xx.ravel(), yy.ravel()]).T
Z = linear_svm.decision_function(xy).reshape(xx.shape)

plt.scatter(pass_ratio[category == 0], shot_ratio[category == 0], c='r', marker = 'o')
plt.scatter(pass_ratio[category == 1], shot_ratio[category == 1], c='b', marker = '^')
plt.contour(xx, yy, Z, colors='k', levels=[-1, 0, 1], alpha=0.5, linestyles=['--', '-', '--'])
plt.title("playing style discrimination with SVM")
plt.xlabel('pass ratio')
plt.ylabel('shot ratio')
plt.show()
33 changes: 33 additions & 0 deletions 18 code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import pandas as pd
import numpy as np
import scipy as sp
import matplotlib.pyplot as plt
from sklearn import svm

ratio = []

rawstat = pd.read_table('/Users/wangtianyi/Documents/python_work/linear inseparable.csv')
category = rawstat.iloc[:,0]
pass_ratio = rawstat.iloc[:,1] / rawstat.iloc[:,2]
shot_ratio = rawstat.iloc[:,3] / rawstat.iloc[:,4]

ratio.append(pass_ratio)
ratio.append(shot_ratio)
ratio = np.array(ratio)
ratio = ratio.astype('float')

linear_svm = svm.SVC(kernel='rbf', gamma=5, C=1e6).fit(ratio.T, category)

x_min, x_max = ratio[0].min() - 0.05, ratio[0].max() + 0.05
y_min, y_max = ratio[1].min() - 0.05, ratio[1].max() + 0.05
xx, yy = np.meshgrid(np.arange(x_min, x_max, 0.01), np.arange(y_min, y_max, 0.01))
xy = np.vstack([xx.ravel(), yy.ravel()]).T
Z = linear_svm.decision_function(xy).reshape(xx.shape)

plt.scatter(pass_ratio[category == 0], shot_ratio[category == 0], c='r', marker = 'o')
plt.scatter(pass_ratio[category == 1], shot_ratio[category == 1], c='b', marker = '^')
plt.contour(xx, yy, Z, colors='k', levels=[-1, 0, 1], alpha=0.5, linestyles=['--', '-', '--'])
plt.title("playing style discrimination with kernel SVM")
plt.xlabel('pass ratio')
plt.ylabel('shot ratio')
plt.show()
77 changes: 77 additions & 0 deletions linear inseparable.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
category long pass short pass header shot kick shot
0.00 52.00 767.00 2.00 12.00
0.00 61.00 557.00 2.00 17.00
0.00 48.00 624.00 2.00 17.00
0.00 41.00 735.00 2.00 11.00
0.00 41.00 643.00 4.00 24.00
0.00 34.00 743.00 5.00 20.00
0.00 49.00 647.00 5.00 13.00
0.00 42.00 887.00 3.00 18.00
0.00 43.00 804.00 1.00 14.00
0.00 56.00 902.00 1.00 14.00
0.00 45.00 614.00 1.00 8.00
0.00 45.00 774.00 0.00 12.00
0.00 36.00 734.00 2.00 13.00
0.00 31.00 803.00 3.00 23.00
0.00 31.00 774.00 0.00 24.00
0.00 48.00 591.00 0.00 14.00
0.00 33.00 842.00 2.00 21.00
0.00 57.00 433.00 2.00 18.00
0.00 49.00 895.00 3.00 11.00
0.00 37.00 824.00 2.00 20.00
0.00 39.00 632.00 1.00 14.00
0.00 41.00 857.00 2.00 16.00
0.00 51.00 660.00 1.00 10.00
0.00 44.00 814.00 2.00 19.00
0.00 51.00 685.00 0.00 19.00
0.00 70.00 663.00 2.00 18.00
0.00 43.00 706.00 2.00 17.00
0.00 51.00 635.00 0.00 9.00
0.00 46.00 970.00 0.00 13.00
0.00 60.00 818.00 0.00 17.00
0.00 51.00 955.00 1.00 17.00
0.00 47.00 595.00 3.00 17.00
0.00 77.00 474.00 0.00 17.00
0.00 51.00 995.00 3.00 16.00
0.00 43.00 864.00 0.00 19.00
0.00 59.00 743.00 3.00 12.00
0.00 31.00 861.00 1.00 18.00
0.00 41.00 599.00 1.00 12.00
1.00 76.00 213.00 4.00 12.00
1.00 73.00 198.00 3.00 5.00
1.00 58.00 312.00 5.00 5.00
1.00 68.00 457.00 1.00 11.00
1.00 65.00 257.00 3.00 3.00
1.00 67.00 236.00 2.00 5.00
1.00 72.00 253.00 2.00 7.00
1.00 75.00 347.00 0.00 5.00
1.00 70.00 271.00 1.00 6.00
1.00 69.00 210.00 3.00 4.00
1.00 71.00 399.00 2.00 7.00
1.00 59.00 359.00 2.00 5.00
1.00 74.00 220.00 0.00 5.00
1.00 69.00 374.00 2.00 6.00
1.00 79.00 373.00 6.00 14.00
1.00 74.00 373.00 2.00 5.00
1.00 75.00 253.00 3.00 3.00
1.00 51.00 432.00 1.00 11.00
1.00 67.00 464.00 4.00 13.00
1.00 71.00 374.00 8.00 9.00
1.00 71.00 297.00 4.00 10.00
1.00 68.00 381.00 0.00 10.00
1.00 86.00 310.00 4.00 11.00
1.00 80.00 326.00 4.00 11.00
1.00 60.00 210.00 0.00 3.00
1.00 80.00 288.00 2.00 6.00
1.00 65.00 401.00 3.00 5.00
1.00 83.00 372.00 2.00 8.00
1.00 74.00 331.00 3.00 6.00
1.00 69.00 347.00 0.00 6.00
1.00 83.00 308.00 3.00 8.00
1.00 92.00 367.00 3.00 5.00
1.00 62.00 473.00 1.00 14.00
1.00 68.00 274.00 4.00 6.00
1.00 69.00 334.00 3.00 10.00
1.00 76.00 309.00 1.00 8.00
1.00 70.00 165.00 3.00 6.00
1.00 60.00 356.00 1.00 6.00

0 comments on commit a1e41be

Please sign in to comment.