teste apply

This commit is contained in:
matheus_cascalho 2020-12-02 18:19:54 -03:00
parent 5e4eb03b89
commit 41818258b2
2 changed files with 35 additions and 8 deletions

View File

@ -6,7 +6,7 @@ import SimpSOM as sps
from pyFTS.models.multivariate import wmvfts from pyFTS.models.multivariate import wmvfts
from typing import Tuple from typing import Tuple
from pyFTS.common.Transformations import Transformation from pyFTS.common.Transformations import Transformation
from typing import List
class SOMTransformation(Transformation): class SOMTransformation(Transformation):
def __init__(self, def __init__(self,
@ -22,14 +22,27 @@ class SOMTransformation(Transformation):
self.name = 'Kohonen Self Organizing Maps FTS' self.name = 'Kohonen Self Organizing Maps FTS'
self.shortname = 'SOM-FTS' self.shortname = 'SOM-FTS'
# def apply(self, data, endogen_variable, param, **kwargs): #TODO(CASCALHO) MELHORAR DOCSTRING def apply(self,
# """ data: pd.DataFrame,
# Transform dataset from M-DIMENSION to 3-dimension endogen_variable=None,
# """ names: List[str] = ['x', 'y'],
# pass param=None,
**kwargs): #TODO(CASCALHO) MELHORAR DOCSTRING
"""
Transform dataset from M-DIMENSION to 3-dimension
"""
if self.net is None:
cols = data.columns[:-1]
train = data[cols]
self.train(data=train)
new_data = self.net.project(data.values)
new_data = pd.DataFrame(new_data, columns=names)
endogen = endogen_variable if endogen_variable is not None else data.columns[-1]
new_data[endogen] = data[endogen]
return new_data
def __repr__(self): def __repr__(self):
status = "is trained" if self.is_trained else "not trained" status = "is trained" if self.net is not None else "not trained"
return f'{self.name}-{status}' return f'{self.name}-{status}'
def __str__(self): def __str__(self):

View File

@ -2,10 +2,22 @@ import unittest
from pyFTS.common.transformations.som import SOMTransformation from pyFTS.common.transformations.som import SOMTransformation
import pandas as pd import pandas as pd
import os import os
import numpy as np
class MyTestCase(unittest.TestCase): class MyTestCase(unittest.TestCase):
def test_apply(self): def test_apply(self):
self.assertEqual(True, False) data = [
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
[1, 1, 1, 1, 1],
]
som = self.som_transformer_trained()
transformed = som.apply(data=pd.DataFrame(data))
uniques = np.unique(transformed)
self.assertEqual(1, len(uniques.shape))
self.assertEqual(3, transformed.values.shape[1])
def test_save_net(self): def test_save_net(self):
som_transformer = self.som_transformer_trained() som_transformer = self.som_transformer_trained()
@ -22,6 +34,8 @@ class MyTestCase(unittest.TestCase):
self.assertEqual(True, is_in_files) self.assertEqual(True, is_in_files)
# def
def test_train(self): def test_train(self):
self.assertEqual() self.assertEqual()