Socket
Book a DemoInstallSign in
Socket

train-test-split

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

train-test-split

Randomly split an array of data into a train and test dataset.

1.0.0
latest
npmnpm
Version published
Weekly downloads
46
43.75%
Maintainers
1
Weekly downloads
 
Created
Source

train-test-split

Build Status Codecov Status

Split your dataset into training and test datasets.

Parameters

trainTestSplit(data, train, seed = null, indices = false);
  • data: the array of data you intend to split.
  • train: size of training set. If less than 1, assumed to be a fraction. E.g., a value of 0.8 will be interpreted as 80% while a value of 4 will be interpreted as 4 records.
  • seed: when set, results will be repeatable if the same seed is used. I.e., the same dataset with the same seed will always yield the same train-test split.
  • indices: indicates whether to return the indices of the provided array or the actual values.

Example usage

const trainTestSplit = require('train-test-split');

const arr = ['one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine', 'ten'];
const [train, test] = trainTestSplit(arr, 0.8, 1234);
console.log(train, test);
// [ 'one', 'seven', 'eight', 'ten', 'six', 'five', 'three', 'four' ] [ 'nine', 'two' ]

const [trainIndices, testIndices] = trainTestSplit(arr, 0.8, 1234, true);
console.log(trainIndices, testIndices);
// [ 0, 6, 7, 9, 5, 4, 2, 3 ] [ 8, 1 ]

Keywords

machine

FAQs

Package last updated on 14 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.