Compare commits

...

2 Commits

Author SHA1 Message Date
matheus_cascalho
efda0cd115 retirada do escopo main do arquivo pca.py 2021-01-12 15:06:54 -03:00
matheus_cascalho
bbf2e2ac67 transformação por PCA 2021-01-12 00:00:05 -03:00

View File

@ -0,0 +1,22 @@
from sklearn.decomposition import PCA
from pyFTS.common.Transformations import Transformation
import pandas as pd
class PCATransformation(Transformation):
def __init__(self):
self.pca = PCA(n_components=2)
self.is_multivariate = True
def apply(self, data, param=None, **kwargs):
endogen_variable = kwargs.get('endogen_variable', None)
names = kwargs.get('names', ('x', 'y'))
if endogen_variable not in data.columns:
endogen_variable = None
cols = data.columns[:-1] if endogen_variable is None else [col for col in data.columns if
col != endogen_variable]
self.pca.fit(data[cols].values)
transformed = self.pca.transform(data[cols])
new = pd.DataFrame(transformed, columns=list(names))
new[endogen_variable] = data[endogen_variable].values
return new