Home
API
Examples
Github
Home
API
Examples
Github
  • API

    • cluster

      • KMeans
    • datasets

      • Boston
      • HeartDisease
      • Iris
    • decomposition

      • PCA
    • ensemble

      • BaggingClassifier
      • RandomForestClassifier
    • feature_extraction

      • CountVectorizer
    • linear_model

      • Lasso
      • LinearRegression
      • LogisticRegression
      • Ridge
      • SGDClassifier
      • SGDRegressor
    • metrics

      • accuracyScore
      • confusion_matrix
      • mean_absolute_error
      • mean_squared_error
      • mean_squared_log_error
      • zeroOneLoss
    • model_selection

      • KFold
      • train_test_split
    • naive_bayes

      • GaussianNB
      • MultinomialNB
    • neighbors

      • KNeighborsClassifier
    • preprocessing

      • Binarizer
      • Imputer
      • LabelEncoder
      • MinMaxScaler
      • OneHotEncoder
      • PolynomialFeatures
      • add_dummy_feature
      • normalize
    • svm

      • BaseSVM
      • NuSVC
      • NuSVR
      • OneClassSVM
      • SVC
      • SVR
    • tree

      • DecisionTreeClassifier

model_selection.train_test_split

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

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:125

Parameters:

ParamTypeDefaultDescription
Xany[][]nullinput data
yany[]nulltarget data
options.clonebooleantrue
options.random_statenumber0
options.test_sizenumber0.25
options.train_sizenumber0.75

Returns:

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