Пример #1
0
def train_test_split(data, test_size=0.3, shuffle=True, random_state=None):
    """Split DataFrame into random train and test subsets

    Parameters
    ----------
    data : pandas dataframe, need to split dataset.

    test_size : float
        If float, should be between 0.0 and 1.0 and represent the
        proportion of the dataset to include in the train split.

    random_state : int, RandomState instance or None, optional (default=None)
        If int, random_state is the seed used by the random number generator;
        If RandomState instance, random_state is the random number generator;
        If None, the random number generator is the RandomState instance used
        by `np.random`.

    shuffle : boolean, optional (default=None)
        Whether or not to shuffle the data before splitting. If shuffle=False
        then stratify must be None.
    """

    if shuffle:
        data = reset(data, random_state=random_state)

    train_size = 1 - test_size
    test_dataset = data[int(len(data) * train_size):].reset_index(drop=True)
    train_dataset = data[:int(len(data) * train_size)].reset_index(drop=True)

    return train_dataset, test_dataset
Пример #2
0
def train_test_split(df, test_size=0.3, shuffle=False, random_state=None):
    if shuffle:
        df = reset(df, random_state=random_state)
    traindf = df[int(len(df) * test_size):]
    testdf = df[:int(len(df) * test_size)]

    return traindf, testdf
Пример #3
0
def train_test_split(data_df, test_size=0.2, shuffle=True, random_state=None):
    if shuffle:
        data_df = reset(data_df, random_state=random_state)

    train = data_df[int(len(data_df) * test_size):].reset_index(drop=True)
    test = data_df[: int(len(data_df) * test_size)].reset_index(drop=True)

    return train, test