Example #1
0
class PimaIndiansExample:
    """ Runs Pima Indians Example.
    More info: https://machinelearningmastery.com/standard-machine-learning-datasets/
    Dataset source: https://machinelearningmastery.com/standard-machine-learning-datasets/"""
    def __init__(self, algorithm):
        self.dataset = pd.read_csv('data/indian-dataset.txt')
        self.algorithm = Classification(algorithm)

    def run(self):
        """
        Runs example.
        """
        X_train, X_test, y_train, y_test = self.__prepare_data(
            'Class', 'Class')
        self.algorithm.train_model(X_train, X_test, y_train, y_test)

    def __prepare_data(self, drop_columns, output_column):
        """
        Splits the data into train and test batches.
        :param drop_columns: columns to drop
        :param output_column: output column
        :returns: Data split into X_train, X_test, y_train, y_test
        """
        columns = [
            "No times pregnant", "Plasma glucose", "blood pressure",
            "skinfold thickness", "2-Hour serum insulin", "BMI",
            "Diabetes pedigree function", "Age", "Class"
        ]
        self.dataset.columns = columns
        X = self.dataset.drop(drop_columns, axis='columns')
        y = self.dataset[output_column]
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.2)
        return X_train, X_test, y_train, y_test
Example #2
0
class Cifar10Example:
    """ Runs CIFAR10 example. Uses keras (tensorflow) to fetch dataset"""

    def __init__(self, algorithm):
        self.dataset = cifar10.load_data()
        self.algorithm = Classification(algorithm)

    def run(self):
        """
        Runs example.
        """
        X_train, X_test, y_train, y_test = self.__prepare_data()
        self.algorithm.train_model(X_train, X_test, y_train, y_test)

    def __prepare_data(self):
        """
        Prepares the data. Based on
        'athena.ecs.csus.edu/~hoangkh/Image Classification with Fashion-MNIST and CIFAR-10.html'.
        :returns: Data split into X_train, X_test, y_train, y_test
        """
        (X_train, y_train), (X_test, y_test) = self.dataset

        X_train = X_train.astype('float32')
        X_test = X_test.astype('float32')
        X_train /= 255
        X_test /= 255

        x_train_flat = X_train.reshape(X_train.shape[0], X_train.shape[1] * X_train.shape[2] * X_train.shape[3])
        x_test_flat = X_test.reshape(X_test.shape[0], X_test.shape[1] * X_test.shape[2] * X_test.shape[3])

        y_train = y_train.reshape(y_train.shape[0], )
        y_test = y_test.reshape(y_test.shape[0], )
        return x_train_flat, x_test_flat, y_train, y_test
Example #3
0
class FashionMNISTExample:
    """ Runs Fashion MNIST Example.
    More info: https://github.com/zalandoresearch/fashion-mnist"""

    def __init__(self, algorithm):
        self.dataset = pd.read_csv('data/Fashion-MNIST/train.csv')
        self.algorithm = Classification(algorithm)

    def run(self):
        """
        Runs example.
        """
        X_train, X_test, y_train, y_test = self.__prepare_data(['Id', 'Category'], 'Category')
        self.algorithm.train_model(X_train, X_test, y_train, y_test)

    def __prepare_data(self, drop_columns, output_column):
        """
        Splits the data into train and test batches.
        :param drop_columns: columns to drop
        :param output_column: output column
        :returns: Data split into X_train, X_test, y_train, y_test
        """
        X = self.dataset.drop(drop_columns, axis='columns')
        y = self.dataset[output_column]
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2)
        return X_train, X_test, y_train, y_test
Example #4
0
class LetterRecognitionExample:
    """ Runs Lette rRecognition Example.
    Dataset source: https://archive.ics.uci.edu/ml/datasets/letter+recognition?fbclid=IwAR0VhB2EGYaFlHO2xaUuDbEvhBgmBGcvdoFGOKUBxk3nVa8926zsL3DF-Nk """
    def __init__(self, algorithm):
        self.dataset = pd.read_csv('data/letter-recognition.data')
        self.algorithm = Classification(algorithm)

    def run(self):
        """
        Runs example.
        """
        X_train, X_test, y_train, y_test = self.__prepare_data(
            'Letter', 'Letter')
        self.algorithm.train_model(X_train, X_test, y_train, y_test)

    def __prepare_data(self, drop_columns, output_column):
        """
        Splits the data into train and test batches.
        :param drop_columns: columns to drop
        :param output_column: output column
        :returns: Data split into X_train, X_test, y_train, y_test
        """
        columns = [
            "Letter", "x-box horizontal pos", "y-box vertical pos", "width",
            "height", "onpix total #", "x-bar mean x of on pixels",
            "y-bar mean y of on pixels", "x2bar mean x var",
            "y2bar mean y var", "xybar mean x y correl",
            "x2ybr mean of x * x * y", "xy2br mean of x * y * y",
            "x-ege mean edge count left to right",
            "xegvy correlation of x-ege with y",
            "y-ege mean edge count bottom to top",
            "yegvx correlation of y-ege with x"
        ]
        self.dataset.columns = columns
        X = self.dataset.drop(drop_columns, axis='columns')
        y = self.dataset[output_column]
        X_train, X_test, y_train, y_test = train_test_split(X,
                                                            y,
                                                            test_size=0.2)
        return X_train, X_test, y_train, y_test
Example #5
0
 def __init__(self, algorithm):
     self.dataset = pd.read_csv('data/indian-dataset.txt')
     self.algorithm = Classification(algorithm)
Example #6
0
 def __init__(self, algorithm):
     self.dataset = cifar10.load_data()
     self.algorithm = Classification(algorithm)
Example #7
0
 def __init__(self, algorithm):
     self.dataset = pd.read_csv('data/letter-recognition.data')
     self.algorithm = Classification(algorithm)
Example #8
0
 def __init__(self, algorithm):
     self.dataset = pd.read_csv('data/Fashion-MNIST/train.csv')
     self.algorithm = Classification(algorithm)