Python utils.split_data() Examples

The following are 7 code examples of utils.split_data(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module utils , or try the search function .
Example #1
Source File: normal_experiment.py    From blood-glucose-prediction with GNU General Public License v3.0 6 votes vote down vote up
def load_dataset(cfg):
    length_std  = float(cfg['length_std'])
    length_mean = float(cfg['length_mean'])
    noise_std   = float(cfg['noise_std'])
    length      = int(cfg['length'])
    nb_past_steps   = int(cfg['nb_past_steps'])
    nb_future_steps = int(cfg['nb_future_steps'])
    train_fraction  = float(cfg['train_fraction'])
    test_fraction   = float(cfg['test_fraction'])
    valid_fraction  = float(cfg['valid_fraction'])

    sequence = generate_sequence(length_std, length_mean, noise_std, length)

    xs, ys = utils.sequence_to_supervised(sequence, nb_past_steps, nb_future_steps)
    xs = np.expand_dims(xs, axis=2)
    ys = np.expand_dims(ys, axis=1)

    x_train, x_valid, x_test = utils.split_data(xs, train_fraction,
            valid_fraction, test_fraction)

    y_train, y_valid, y_test = utils.split_data(ys, train_fraction,
            valid_fraction, test_fraction)

    return x_train, y_train, x_valid, y_valid, x_test, y_test 
Example #2
Source File: device_sequence_classifier.py    From IoT-device-type-identification with MIT License 6 votes vote down vote up
def find_opt_seq_len(self, validation, update=True):
        # Finds minimal seq length s.t accuracy=1 on all sessions
        opt_seq_len = 1
        # Find minimal sequence length s.t FPR=1 for all other devs
        for dev_name, dev_sessions in validation.groupby('device_category'):
            dev_sessions = utils.split_data(dev_sessions, y_col=self.y_col)[0]
            is_dev = self.is_dev(dev_name)
            start = 0
            seq_len = 1
            while start + seq_len < len(dev_sessions):
                is_dev_pred = (self.predict([dev_sessions[start:start + seq_len]]))[0]
                if is_dev == is_dev_pred:
                    start += 1
                else:
                    start = max(1, start-2)
                    seq_len += 2
            opt_seq_len = max(seq_len, opt_seq_len)
        # Return minimal seq length s.t accuracy=1
        if update:
            self.opt_seq_len = opt_seq_len
        return opt_seq_len 
Example #3
Source File: ohio.py    From blood-glucose-prediction with GNU General Public License v3.0 5 votes vote down vote up
def load_data(cfg):
    xml_path        = cfg['xml_path']
    nb_past_steps   = int(cfg['nb_past_steps'])
    nb_future_steps = int(cfg['nb_future_steps'])
    train_fraction  = float(cfg['train_fraction'])
    valid_fraction  = float(cfg['valid_fraction'])
    test_fraction   = float(cfg['test_fraction'])

    xs, ys = load_glucose_data(xml_path, nb_past_steps, nb_future_steps)
    ys = np.expand_dims(ys, axis=1)

    x_train, x_valid, x_test = utils.split_data(xs, train_fraction,
            valid_fraction, test_fraction)
    y_train, y_valid, y_test = utils.split_data(ys, train_fraction,
            valid_fraction, test_fraction)

    # scale data
    scale = float(cfg['scale'])
    x_train *= scale
    y_train *= scale
    x_valid *= scale
    y_valid *= scale
    x_test  *= scale
    y_test  *= scale

    return x_train, y_train, x_valid, y_valid, x_test, y_test 
Example #4
Source File: device_sequence_classifier.py    From IoT-device-type-identification with MIT License 5 votes vote down vote up
def split_data(self, data):
        data = utils.clear_missing_data(data)
        x = []
        y = []
        for dev_name, dev_sessions in data.groupby(self.y_col):
            dev_sessions = dev_sessions.drop(['device_category'], axis=1)
            dev_sessions = utils.perform_feature_scaling(dev_sessions)
            is_dev = self.is_dev(dev_name)
            seqs = self.get_sub_sequences(dev_sessions)
            x += seqs
            y += [is_dev]*len(seqs)
        return x, y 
Example #5
Source File: multiple_device_classifier.py    From IoT-device-type-identification with MIT License 5 votes vote down vote up
def eval_on_dataset(self, dataset, is_dataset_csv=False):
        if is_dataset_csv:
            dataset = utils.load_data_from_csv(dataset, self.use_cols)
        # Split data to features and labels
        x, y_true = utils.split_data(dataset, self.y_col)
        # Classify data
        y_pred = self.predict(x)
        # Evaluate predictions
        return utils.eval_predictions(y_true, y_pred) 
Example #6
Source File: device_session_classifier.py    From IoT-device-type-identification with MIT License 5 votes vote down vote up
def train(self, train):
        x_train, y_train = utils.split_data(train, y_col=self.y_col)
        self.model.fit(x_train, y_train) 
Example #7
Source File: device_session_classifier.py    From IoT-device-type-identification with MIT License 5 votes vote down vote up
def split_data(self, data):
        x, y = utils.split_data(data, self.y_col)
        y = self.get_is_dev_vec(y)
        return x, y