-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinal Project.py
More file actions
62 lines (49 loc) · 2 KB
/
Final Project.py
File metadata and controls
62 lines (49 loc) · 2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import numpy as np
import math
import matplotlib.pyplot as plt
import pickle
from sklearn import tree
import pandas as pd
def convert(value):
try:
# Try to convert to float
return int(value)
except ValueError:
# If it fails, encode as hex
return value.encode('utf-8').hex()
def decode_hex(value):
try:
# Try to decode assuming it's hex
return bytes.fromhex(value).decode('utf-8')
except ValueError:
# If it fails (it's just a number), leave it as-is
return value
if __name__ == '__main__':
# Load the training data
filename = f'./wcmatches.csv'
#M = np.genfromtxt('./wcmatches.csv', missing_values=0, skip_header=0, delimiter=',', dtype=int)
M = np.genfromtxt('./wcmatches.csv', skip_header=0, delimiter=',', dtype=str)
# Step 3: Apply it across the entire array
vectorized_convert = np.vectorize(convert) # Applies function to every element
converted_data = vectorized_convert(M)
# Step 2: Vectorize it to apply over the array
vectorized_decode = np.vectorize(decode_hex, otypes=[str])
decoded_data = vectorized_decode(converted_data)
print(decoded_data)
#create filter
country_list = ['Brazil', 'Germany', 'Italy', 'Argentina', 'France', 'Spain', 'England', 'Uruguay']
hex_vals = vectorized_convert(country_list)
print(f'hex vals: {hex_vals}')
#target_value = 'Uruguay'.encode('utf-8').hex()
#print(f'target value: {target_value}')
# Find which rows match
mask = np.isin(converted_data[:, 1], hex_vals)
# Apply the mask to get the filtered rows
filtered_rows = converted_data[mask]
decoded_data = vectorized_decode(filtered_rows)
print(decoded_data)
#M = np.genfromtxt('./FIFA - 2014.csv', missing_values=0, skip_header=0, delimiter=',', dtype=int)
ytrn = converted_data[:, 3]
Xtrn = converted_data[:, 4:]
#print(f'ytest: {ytrn}')
#print(f'Xtst: {Xtrn}')