How to split train test data using sklearn and python?
1

How to split train test data using sklearn and python?

This recipe helps you split train test data using sklearn and python
In [1]:
## How to split train test data using sklearn and python
def Snippet_131():
    print()
    print(format('How to split train test data using sklearn and python','*^82'))

    import warnings
    warnings.filterwarnings("ignore")

    # load libraries
    from sklearn import datasets
    from sklearn.model_selection import train_test_split

    # Load the digits dataset
    digits = datasets.load_digits()

    # Create the features matrix
    X = digits.data
    print(); print(X.shape)

    # Create the target vector
    y = digits.target
    print(); print(y.shape)

    # Create training and test sets
    X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33,
                                                        random_state=42)
    print(); print(X_train.shape)
    print(); print(X_test.shape)
    print(); print(y_train.shape)
    print(); print(y_test.shape)

Snippet_131()
**************How to split train test data using sklearn and python***************

(1797, 64)

(1797,)

(1203, 64)

(594, 64)

(1203,)

(594,)