Beispiel #1
0
    def test_where_all_are_true(self):
        M = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
        col_names = ['heigh', 'weight', 'age']
        lables = [0, 0, 1]
        M = eights.utils.cast_list_of_list_to_sa(M, col_names=col_names)

        arguments = [{
            'func': val_eq,
            'col_name': 'heigh',
            'vals': 1
        }, {
            'func': val_lt,
            'col_name': 'weight',
            'vals': 3
        }, {
            'func': val_between,
            'col_name': 'age',
            'vals': (3, 4)
        }]

        res = where_all_are_true(M, arguments, 'eq_to_stuff')
        ctrl = np.array([(1, 2, 3, True), (2, 3, 4, False), (3, 4, 5, False)],
                        dtype=[('heigh', '<i8'), ('weight', '<i8'),
                               ('age', '<i8'), ('eq_to_stuff', '?')])

        self.assertTrue(np.array_equal(res, ctrl))
Beispiel #2
0
    def test_where_all_are_true(self):
        M = [[1,2,3], [2,3,4], [3,4,5]]
        col_names = ['heigh','weight', 'age']
        lables= [0,0,1]
        M = eights.utils.cast_list_of_list_to_sa(
            M,
            col_names=col_names)

        arguments = [{'func': val_eq, 'col_name': 'heigh', 'vals': 1},
                     {'func': val_lt, 'col_name': 'weight', 'vals': 3},
                     {'func': val_between, 'col_name': 'age', 'vals': 
                      (3, 4)}]

        res = where_all_are_true(
            M, 
            arguments,
            'eq_to_stuff')
        ctrl = np.array(
            [(1, 2, 3, True), (2, 3, 4, False), (3, 4, 5, False)], 
            dtype=[('heigh', '<i8'), ('weight', '<i8'), ('age', '<i8'),
                   ('eq_to_stuff', '?')])
                   
        self.assertTrue(np.array_equal(res, ctrl))
if False:
    plot_correlation_scatter_plot(M)
    plot_correlation_matrix(M)
    plot_kernel_density(M["f0"])  # no designation of col name
    plot_box_plot(M["f0"])  # no designation of col name


if False:
    from eights.generate import val_between, where_all_are_true, append_cols  # val_btwn, where

    # generate a composite rule
    M = where_all_are_true(
        M,
        [
            {"func": val_between, "col_name": "f0", "vals": (3.5, 5.0)},
            {"func": val_between, "col_name": "f1", "vals": (2.7, 3.1)},
        ],
        "a new col_name",
    )

    # new eval function
    def rounds_to_val(M, col_name, boundary):
        return np.round(M[col_name]) == boundary

    M = where_all_are_true(M, [{"func": rounds_to_val, "col_name": "f0", "vals": 5}], "new_col")

    from eights.truncate import fewer_then_n_nonzero_in_col, remove_rows_where, remove_cols, val_eq

    # remove Useless row
    M = fewer_then_n_nonzero_in_col(M, 1)
    M = append_cols(M, labels, "labels")
Beispiel #4
0
        print x

if False:
    plot_correlation_scatter_plot(M)
    plot_correlation_matrix(M)
    plot_kernel_density(M['f0'])  #no designation of col name
    plot_box_plot(M['f0'])  #no designation of col name

if False:
    from eights.generate import val_between, where_all_are_true, append_cols  #val_btwn, where
    #generate a composite rule
    M = where_all_are_true(M, [{
        'func': val_between,
        'col_name': 'f0',
        'vals': (3.5, 5.0)
    }, {
        'func': val_between,
        'col_name': 'f1',
        'vals': (2.7, 3.1)
    }], 'a new col_name')

    #new eval function
    def rounds_to_val(M, col_name, boundary):
        return (np.round(M[col_name]) == boundary)

    M = where_all_are_true(M, [{
        'func': rounds_to_val,
        'col_name': 'f0',
        'vals': 5
    }], 'new_col')