text_html_output_1.png
from sklearn.preprocessing import StandardScaler

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

df_fifa = pd.read_csv('/kaggle/input/fifa19/data.csv')

columns_to_drop = ['Unnamed: 0', 'ID', 'Name', 'Photo', 'Nationality', 'Flag', 'Club', 'Club Logo', 'Value', 'Wage', 'Special', 'Preferred Foot', 'International Reputation', 'Weak Foot', 'Skill Moves', 'Work Rate', 'Body Type', 'Real Face', 'Position', 'Jersey Number', 'Joined', 'Loaned From', 'Contract Valid Until', 'Height', 'Weight', 'LS', 'ST', 'RS', 'LW', 'LF', 'CF', 'RF', 'RW', 'LAM', 'CAM', 'RAM', 'LM', 'LCM', 'CM', 'RCM', 'RM', 'LWB', 'LDM', 'CDM', 'RDM', 'RWB', 'LB', 'LCB', 'CB', 'RCB', 'RB', 'Release Clause']
df_fifa.drop(columns_to_drop, axis=1, inplace=True)

df_fifa = df_fifa.dropna()
x = df_fifa.drop('Overall', axis=1).values
y = df_fifa.Overall.values

x = StandardScaler().fit_transform(x)

mx_cov = np.cov(x, rowvar=False)

mx_exemplo = np.array([[1.76, 75], [1.8, 97.3]])
mx_exemplo.T

np.shape(mx_cov)

autovalores, autovetores = np.linalg.eig(mx_cov)

tp_componentes = tuple(zip(autovalores, autovetores))
tp_componentes

total = sum(autovalores)
var_acum = [autovalor / total for autovalor in sorted(autovalores, reverse=True)]
var_acum

componentes = np.argmax(np.cumsum(var_acum) >= 0.95)
ft_ds = tp_componentes[:componentes]
ft_vetor = list()
for val, vet in ft_ds:
    ft_vetor.append(vet)
df = pd.DataFrame(np.array(ft_vetor).T[:15])
np.shape(ft_vetor)

featured_ds = np.dot(x[:, :15], np.array(ft_vetor).T[:15]) + x.mean()
df = pd.DataFrame(featured_ds)
df