# Path: percept/fields/base.py
# class Complex(ValueField):
#     """
#     Store complex objects, such as classes
#     """
#     def to_json(self, value):
#         return pickle.dumps(value)
# 
#     def from_json(self, value):
#         try:
#             new_value = pickle.loads(value)
#         except Exception:
#             log.exception("Could not unpickle value. : {0}".format(value))
#             new_value = None
#         return new_value
# 
# class List(ValueField):
#     """
#     Store lists
#     """
#     default = []
# 
# Path: percept/conf/base.py
# class Settings(object):
#     def _initialize(self, settings_module):
#     def _setup(self):
#     def __getattr__(self, name):
#     def _configure_logging(self):
#     def configured(self):
# 
# Path: percept/utils/models.py
# class RegistryCategories(object):
#     """
#     Define valid registry categories
#     """
#     base = "base"
#     preprocessors = "preprocessors"
#     inputs = "inputs"
#     formatters = "formatters"
#     algorithms = "algorithms"
#     workflows = "workflows"
# 
# Path: percept/tests/framework.py
# class SVMTester(Tester):
#     test_case_format = {'data' : basestring, 'target' : basestring, 'dataformat' : basestring}
# 
#     def test(self, **kwargs):
#         super(SVMTester, self).test(**kwargs)
#         datafile = kwargs.get('data')
#         targetfile = kwargs.get('target')
#         dataformat = kwargs.get('dataformat')
# 
#         inst = self.cls()
#         output_format = inst.data_format
#         data = self.read_and_reformat(output_format, datafile, dataformat)
#         target = self.read_and_reformat(output_format, targetfile, dataformat)
# 
#         inst.train(data, target)
#         assert inst.clf is not None
# 
#         prediction = inst.predict(data)
#         assert isinstance(prediction, np.ndarray)
# 
# Path: percept/utils/input.py
# class DataFormats(object):
#     """
#     Define acceptable data formats
#     """
#     csv = "csv"
#     dataframe = "dataframe"


from base import Task
from percept.fields.base import Complex, List
from sklearn import svm
from percept.conf.base import settings
from percept.utils.models import RegistryCategories
from percept.tests.framework import SVMTester
from percept.utils.input import DataFormats
import numpy as np
import os
import logging
"""
Machine learning algorithms to train and predict
"""



log = logging.getLogger(__name__)

class Train(Task):
    """
    A class to train a support vector machine algorithm
    """
    clf = Complex()
    category = RegistryCategories.algorithms
    algorithm = svm.SVC
    args = {'C' : 1.0}
    tester = SVMTester
    test_cases = [
        {
            'data' : os.path.abspath(os.path.join(settings.PACKAGE_PATH,'tests/data/csv/1/data.csv')),

# Path: percept/fields/base.py
# class Complex(ValueField):
#     """
#     Store complex objects, such as classes
#     """
#     def to_json(self, value):
#         return pickle.dumps(value)
# 
#     def from_json(self, value):
#         try:
#             new_value = pickle.loads(value)
#         except Exception:
#             log.exception("Could not unpickle value. : {0}".format(value))
#             new_value = None
#         return new_value
# 
# class List(ValueField):
#     """
#     Store lists
#     """
#     default = []
# 
# Path: percept/conf/base.py
# class Settings(object):
#     def _initialize(self, settings_module):
#     def _setup(self):
#     def __getattr__(self, name):
#     def _configure_logging(self):
#     def configured(self):
# 
# Path: percept/utils/models.py
# class RegistryCategories(object):
#     """
#     Define valid registry categories
#     """
#     base = "base"
#     preprocessors = "preprocessors"
#     inputs = "inputs"
#     formatters = "formatters"
#     algorithms = "algorithms"
#     workflows = "workflows"
# 
# Path: percept/tests/framework.py
# class SVMTester(Tester):
#     test_case_format = {'data' : basestring, 'target' : basestring, 'dataformat' : basestring}
# 
#     def test(self, **kwargs):
#         super(SVMTester, self).test(**kwargs)
#         datafile = kwargs.get('data')
#         targetfile = kwargs.get('target')
#         dataformat = kwargs.get('dataformat')
# 
#         inst = self.cls()
#         output_format = inst.data_format
#         data = self.read_and_reformat(output_format, datafile, dataformat)
#         target = self.read_and_reformat(output_format, targetfile, dataformat)
# 
#         inst.train(data, target)
#         assert inst.clf is not None
# 
#         prediction = inst.predict(data)
#         assert isinstance(prediction, np.ndarray)
# 
# Path: percept/utils/input.py
# class DataFormats(object):
#     """
#     Define acceptable data formats
#     """
#     csv = "csv"
#     dataframe = "dataframe"


# Path: percept/tasks/train.py
from base import Task
from percept.fields.base import Complex, List
from sklearn import svm
from percept.conf.base import settings
from percept.utils.models import RegistryCategories
from percept.tests.framework import SVMTester
from percept.utils.input import DataFormats
import numpy as np
import os
import logging

"""
Machine learning algorithms to train and predict
"""



log = logging.getLogger(__name__)

class Train(Task):
    """
    A class to train a support vector machine algorithm
    """
    clf = Complex()
    category = RegistryCategories.algorithms
    algorithm = svm.SVC
    args = {'C' : 1.0}
    tester = SVMTester
    test_cases = [
        {
            'data' : os.path.abspath(os.path.join(settings.PACKAGE_PATH,'tests/data/csv/1/data.csv')),

            'target' : os.path.abspath(os.path.join(settings.PACKAGE_PATH,'tests/data/csv/1/target.csv')),