Train Test Split - setiamanlhc/python-snippet-code GitHub Wiki

Below code sample uses IRIS dataset.

from sklearn.model_selection import train_test_split

feature_name = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
feature_target = ['species']

X = iris[feature_name]
#unshape data using numpy function ravel
y = np.ravel(iris[feature_target])

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.30, random_state=101)