Recipe: How to split train test data using sklearn and python?
DATA MUNGING

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,)


Stuck at work?
Can't find the recipe you are looking for. Let us know and we will find an expert to create the recipe for you. Click here
Companies using this Recipe
1 developer from HCL
1 developer from Tata Consultancy Services
1 developer from Amazon
1 developer from HvH
1 developer from Vodafone
1 developer from ANAC
1 developer from ICU Medical
1 developer from Exponentia DataLabs
1 developer from Mavenir