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.KFold

Usage

import { KFold } from 'machinelearn/model_selection';

const kFold = new KFold({ k: 5 });
const X1 = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1];
console.log(kFold.split(X1, X1));

/* [ { trainIndex: [ 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 0, 1, 2, 3 ] },
* { trainIndex: [ 0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 4, 5, 6, 7 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 16, 17, 18, 19 ],
*  testIndex: [ 8, 9, 10, 11 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 16, 17, 18, 19 ],
*  testIndex: [ 12, 13, 14, 15 ] },
* { trainIndex: [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 ],
*  testIndex: [ 16, 17, 18, 19 ] } ]

Constructors

  • constructor

Methods

  • split

Constructors


constructor

⊕ KFold(__namedParameters: `object`)

Defined in model_selection/_split.ts:43

Parameters:

ParamTypeDefaultDescription
options.knumber2
options.shufflebooleanfalse

Returns: KFold

Methods


λ split

Defined in model_selection/_split.ts:57

Parameters:

ParamTypeDefaultDescription
Xany[]nullTraining data, where n_samples is the number of samples and n_features is the number of features.
yany[]nullThe target variable for supervised learning problems.

Returns:

any[]

Next
train_test_split