{"id":19267030,"url":"https://github.com/mljs/cross-validation","last_synced_at":"2025-07-13T00:38:55.617Z","repository":{"id":57298966,"uuid":"63337574","full_name":"mljs/cross-validation","owner":"mljs","description":"Utility library to make cross validation with supervised classifiers","archived":false,"fork":false,"pushed_at":"2020-01-31T13:55:05.000Z","size":1322,"stargazers_count":8,"open_issues_count":1,"forks_count":4,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-18T05:20:41.856Z","etag":null,"topics":["classifier","cross-validation","supervised-learning"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mljs.png","metadata":{"files":{"readme":"README.md","changelog":"History.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-07-14T13:10:47.000Z","updated_at":"2025-01-06T10:14:04.000Z","dependencies_parsed_at":"2022-08-26T18:12:41.254Z","dependency_job_id":null,"html_url":"https://github.com/mljs/cross-validation","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcross-validation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcross-validation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcross-validation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mljs%2Fcross-validation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mljs","download_url":"https://codeload.github.com/mljs/cross-validation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250120079,"owners_count":21378135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["classifier","cross-validation","supervised-learning"],"created_at":"2024-11-09T20:09:33.798Z","updated_at":"2025-04-21T19:32:31.788Z","avatar_url":"https://github.com/mljs.png","language":"JavaScript","readme":"# cross-validation\n\n  [![NPM version][npm-image]][npm-url]\n  [![build status][travis-image]][travis-url]\n  [![npm download][download-image]][download-url]\n\nUtility library to do cross validation with supervised classifiers.\n\nCross-validation methods: \n- [k-fold](https://en.wikipedia.org/wiki/Cross-validation_(statistics)#k-fold_cross-validation)\n- [leave-p-out](https://en.wikipedia.org/wiki/Cross-validation_(statistics)#Leave-p-out_cross-validation)\n\n[API documentation](https://mljs.github.io/cross-validation/).\n\nA list of the mljs supervised classifiers is available [here](https://github.com/mljs/ml#tools) in the supervised learning section, but you could also use your own. Cross validations methods return a ConfusionMatrix ([https://github.com/mljs/confusion-matrix](https://github.com/mljs/confusion-matrix)) that can be used to calculate metrics on your classification result.\n\n## Installation\n```bash\nnpm i -s ml-cross-validation\n```\n\n## Example using a ml classification library\n```js\nconst crossValidation = require('ml-cross-validation');\nconst KNN = require('ml-knn');\nconst dataset = [[0, 0, 0], [0, 1, 1], [1, 1, 0], [2, 2, 2], [1, 2, 2], [2, 1, 2]];\nconst labels = [0, 0, 0, 1, 1, 1];\nconst confusionMatrix = crossValidation.leaveOneOut(KNN, dataSet, labels);\nconst accuracy = confusionMatrix.getAccuracy();\n```\n\n## Example using a classifier with its own specific API\nIf you have a library that does not comply with the ML Classifier conventions, you can use can use a callback to perform the classification.\nThe callback will take the train features and labels, and the test features. The callback shoud return the array of predicted labels.\n```js\nconst crossValidation = require('ml-cross-validation');\nconst KNN = require('ml-knn');\nconst dataset = [[0, 0, 0], [0, 1, 1], [1, 1, 0], [2, 2, 2], [1, 2, 2], [2, 1, 2]];\nconst labels = [0, 0, 0, 1, 1, 1];\nconst confusionMatrix = crossValidation.leaveOneOut(dataSet, labels, function(trainFeatures, trainLabels, testFeatures) {\n  const knn = new KNN(trainFeatures, trainLabels);\n  return knn.predict(testFeatures);\n});\nconst accuracy = confusionMatrix.getAccuracy();\n```\n\n## ML classifier API conventions\nYou can write your classification library so that it can be used with ml-cross-validation as described in [here](#example-using-a-ml-classification-library)\nFor that, your classification library must implement\n- A constructor. The constructor can be passed options as a single argument.\n- A `train` method. The `train` method is passed the data as a first argument and the labels as a second.\n- A `predict` method. The `predict` method is passed test data and should return a predicted label.\n\n### Example\n```js\nclass MyClassifier {\n  constructor(options) {\n    this.options = options;\n  }\n  train(data, labels) {\n    // Create your model\n  }\n  predict(testData) {\n    // Apply your model and return predicted label\n    return prediction;\n  }\n}\n```\n### \n\n[npm-image]: https://img.shields.io/npm/v/ml-cross-validation.svg?style=flat-square\n[npm-url]: https://npmjs.org/package/ml-cross-validation\n[travis-image]: https://img.shields.io/travis/mljs/cross-validation/master.svg?style=flat-square\n[travis-url]: https://travis-ci.org/mljs/cross-validation\n[download-image]: https://img.shields.io/npm/dm/ml-cross-validation.svg?style=flat-square\n[download-url]: https://npmjs.org/package/ml-cross-validation\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fcross-validation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmljs%2Fcross-validation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmljs%2Fcross-validation/lists"}