model_selection.train_test_split

train_test_split(X: `object`, y: `object`, __namedParameters: `object`)

Split arrays or matrices into random train and test subsets

Usage

import { train_test_split } from 'machinelearn/model_selection';

const X = [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9]];
const y = [0, 1, 2, 3, 4];

train_test_split(X, y, {
  test_size: 0.33,
  train_size: 0.67,
  random_state: 42
});

/*
* { xTest: [ [ 0, 1 ], [ 8, 9 ] ],
*  xTrain: [ [ 4, 5 ], [ 6, 7 ], [ 2, 3 ] ],
*  yTest: [ 0, 4 ],
*  yTrain: [ 2, 3, 1 ] }

Defined in model_selection/_split.ts:134

Parameters:

ParamTypeDefaultDescription
Xany[][]nullinput data
yany[]nulltarget data
options.clonebooleantrueto clone the original data
options.randomstatenumber0state used to shuffle data
options.testsizenumber0.25size of the returning test set
options.trainsizenumber0.75size of the returning training set

Returns:

ParamTypeDescription
xTestany[]undefined
xTrainany[]undefined
yTestany[]undefined
yTrainany[]undefined