<jupyter_start><jupyter_text>Data Loader Extracting data and adjusting data to numerical ones.  Adding distance and angle by calculating with (x, y) point.<jupyter_code>import numpy as np 
import pandas as pd
import json
import glob

path = './events/*.json'
dfs = []
for file in glob.glob(path):
    with open(file) as f:
        json_data = pd.json_normalize(json.loads(f.read()))
        json_data['site'] = file.rsplit("/", 1)[-1]
    dfs.append(json_data)
data = pd.concat(dfs)

train = pd.DataFrame(data)

path2 = "players.json" 

with open(path2) as f:
    play = json.load(f)

players = pd.DataFrame(play)

pd.unique(train['subEventName'])
shots = train[train['subEventName'] == 'Shot']

shots_model = pd.DataFrame(columns=["Goal","X","Y"], dtype=object)

for i,shot in shots.iterrows():
    
    
    shots_model.at[i,'Header'] = 0
    for tag in shot['tags']:
        if tag['id'] == 403:
            shots_model.at[i,'Header'] = 1
    
    
    #take distance from center of goal at y = 50, x position of goal is always 100
    shots_model.at[i,'X'] = 100-shot['positions'][0]['x']
    shots_model.at[i,'Y'] = shot['positions'][0]['y']
    shots_model.at[i,'C'] = abs(shot['positions'][0]['y'] - 50)
        
    #distance in meters
        
    x = shots_model.at[i,'X']* 105/100
    y = shots_model.at[i,'C']* 65/100
    shots_model.at[i,'Distance'] = np.sqrt(x**2 + y**2)
        
    angle = np.arctan(7.32 * x / (x**2 + y**2 - (7.32/2)**2))
        
    if angle < 0:
        angle = np.pi + angle
        
    shots_model.at[i,'Angle'] = angle
        
    #goal check
    shots_model.at[i,'Goal'] = 0
    shots_model.at[i,'Counter Attack'] = 0
    shots_model.at[i, 'Blocked'] = 0
    shots_model.at[i, 'Right Foot'] = 0
    shots_model.at[i,'wyId'] = shot['playerId']
    
    if shot['matchPeriod'] == '1H':
        shots_model.at[i, 'First Half'] = 1
    
    else:
        shots_model.at[i,'First Half'] = 0
        
    for tags in shot['tags']:
        if tags['id'] == 101:
            shots_model.at[i,'Goal'] = 1
            
        if tags['id'] == 1901:
            shots_model.at[i, 'Counter Attack'] = 1
        
        if tags['id'] == 2101:
            shots_model.at[i, 'Blocked'] = 1
        
        if tags['id'] == 402:
            shots_model.at[i, 'Right Foot'] = 1
            
            
        
shots_model['angle_degrees'] = shots_model['Angle'] * 180 / np.pi

shots_model = shots_model.merge(players, left_on = 'wyId' , right_on = 'wyId')

for i,shot in shots_model.iterrows():
    shots_model.at[i, 'strong foot'] = 0
    
    if shot['Right Foot'] == 1:
        if shot['foot'] == 'right':
            shots_model.at[i, 'strong foot'] = 1
    
    elif shot['Right Foot'] == 0:
        if shot['foot'] == 'left':
            shots_model.at[i, 'strong foot'] = 1<jupyter_output><empty_output><jupyter_text>current data information<jupyter_code>shots_model.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 41843 entries, 0 to 41842
Data columns (total 27 columns):
 #   Column                 Non-Null Count  Dtype  
---  ------                 --------------  -----  
 0   Goal                   41843 non-null  object 
 1   X                      41843 non-null  object 
 2   Y                      41843 non-null  object 
 3   Header                 41843 non-null  float64
 4   C                      41843 non-null  float64
 5   Distance               41843 non-null  float64
 6   Angle                  41843 non-null  float64
 7   Counter Attack         41843 non-null  float64
 8   Blocked                41843 non-null  float64
 9   Right Foot             41843 non-null  float64
 10  wyId                   41843 non-null  float64
 11  First Half             41843 non-null  float64
 12  angle_degrees          41843 non-null  float64
 13  passportArea           41843 non-null  object 
 14  weight                 41843 non-null  int64  
 15  fi[...]<jupyter_text>a brief look to the first row<jupyter_code>shots_model.iloc[1]<jupyter_output><empty_output><jupyter_text>drop out the data that is not related with the goal accuracy<jupyter_code>shots_model.drop(['passportArea', 'firstName','middleName', 'lastName',
                  'birthDate','role', 'birthArea', 'foot', 'shortName', 
                  'currentNationalTeamId'], axis = 1, inplace = True)<jupyter_output><empty_output><jupyter_text>information of new dropped-out dataset<jupyter_code>shots_model.info()<jupyter_output><class 'pandas.core.frame.DataFrame'>
Int64Index: 41843 entries, 0 to 41842
Data columns (total 17 columns):
 #   Column          Non-Null Count  Dtype  
---  ------          --------------  -----  
 0   Goal            41843 non-null  object 
 1   X               41843 non-null  object 
 2   Y               41843 non-null  object 
 3   Header          41843 non-null  float64
 4   C               41843 non-null  float64
 5   Distance        41843 non-null  float64
 6   Angle           41843 non-null  float64
 7   Counter Attack  41843 non-null  float64
 8   Blocked         41843 non-null  float64
 9   Right Foot      41843 non-null  float64
 10  wyId            41843 non-null  float64
 11  First Half      41843 non-null  float64
 12  angle_degrees   41843 non-null  float64
 13  weight          41843 non-null  int64  
 14  currentTeamId   41524 non-null  object 
 15  height          41843 non-null  int64  
 16  strong foot     41843 non-null  float64
dtypes: float64(11), int64(2), objec[...]<jupyter_text>Correlation map using sns to get the correlation map of all features this can give user a good sense of who is positive and negative related to the goal<jupyter_code>from matplotlib import pyplot as plt
import seaborn as sns
import os

#os.mkdir('./image/')

plt.figure(figsize=(16,12))
ax = plt.axes()
sns.heatmap(shots_model.corr(),annot=True,cmap='viridis')
ax.set_title("Features Correlation Map")
#plt.savefig('./image/CorrelationMap_AllEvent.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>Analysis of Distance and Angle by Goal this analysis can help user realized the relation among distance, angle and goal<jupyter_code>plt.figure(figsize=(10,6))
ax = plt.axes()
sns.scatterplot(x = 'Distance', y = 'angle_degrees', hue = 'Goal',size="Goal", sizes=(60, 30), 
                palette='dark', data = shots_model, style="Goal", markers = {0:"^", 1:"o"})
plt.xlabel("Distance (meters)")
plt.ylabel("Angle (degrees)")
ax.set_title("Analysis of Distance and Angle by Goal")
#plt.savefig('./image/DistanceAngle_Analysis.jpg')
plt.show()<jupyter_output><empty_output><jupyter_text>Top View Image of Position and Goal the top view image is a good way to show the distribution of each shooting spot<jupyter_code>plt.figure(figsize=(10,6))
ax = plt.axes()
sns.scatterplot(x = 'X', y = 'Y', hue = 'Goal',size="Goal", sizes=(30, 15), 
                palette='dark', data = shots_model, style="Goal", markers = {0:"X", 1:"o"})
plt.xlabel("X (meters)")
plt.ylabel("Y (degrees)")
ax.set_title("Top View Image of Position and Goal")
#plt.savefig('./image/Position_TopView.jpg')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13227438852965984, 'fraction_numerical': 0.055383750351419736, 'mean_word_length': 2.511846001974334, 'pattern_counts': {'":': 0, '<': 34, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '8', 'dir': 'jupyter-structured-clean-dedup', 'id': '615701', 'license': 'Apache-2.0', 'n_tokens_mistral': 2694, 'n_tokens_neox': 2357, 'n_words': 618, 'path': 'notebooks/Visualization.ipynb', 'repo_name': 'HinanawiTS/ECE-143-Project', 'size': '7114'}