Answers for "how to do train test split of pandas dataframe without shuffle"

5

sklearn split train test

import numpy as np
from sklearn.model_selection import train_test_split

X, y = np.arange(10).reshape((5, 2)), range(5)

X_train, X_test, y_train, y_test = train_test_split(
    X, y, test_size=0.33, random_state=42)

X_train
# array([[4, 5],
#        [0, 1],
#        [6, 7]])

y_train
# [2, 0, 3]

X_test
# array([[2, 3],
#        [8, 9]])

y_test
# [1, 4]
Posted by: Guest on March-04-2020
0

train_test_split without shuffle

from sklearn.model_selection import train_test_split
train_test_split(X, y, test_size=0.2, shuffle=False)
Posted by: Guest on January-14-2021
3

pandas split dataframe to train and test

train=df.sample(frac=0.8,random_state=200) #random state is a seed value
test=df.drop(train.index)
Posted by: Guest on August-02-2020

Code answers related to "how to do train test split of pandas dataframe without shuffle"

Python Answers by Framework

Browse Popular Code Answers by Language