How to use the ml-dataset-iris.getDistinctClasses function in ml-dataset-iris

To help you get started, we’ve selected a few ml-dataset-iris examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mljs / libsvm / benchmark / iris / precomputed-cv-benchmark.js View on Github external
function exec(SVM, time) {
    const MILISECONDS = time * 1000;

    const features = data.getNumbers();
    let labels = data.getClasses();
    const classes = data.getDistinctClasses();
    const c = {};
    classes.forEach((v, idx) => (c[v] = idx));
    labels = labels.map(l => c[l]);

    // We precompute the gaussian kernel
    const kernel = new Kernel('gaussian', {sigma: 1 / Math.sqrt(gamma)});
    const KData = kernel.compute(features).addColumn(0, range(1, labels.length + 1));

    const t1 = Date.now();
    let t2 = Date.now();
    let count = 0;
    while (t2 - t1 < MILISECONDS) {
        const svm = new SVM({
            quiet: true,
            cost: cost,
            kernel: SVM.KERNEL_TYPES.PRECOMPUTED
github mljs / libsvm / benchmark / iris / iris-cv.js View on Github external
async function exec() {
    const SVM = await require(`../../${argv[0]}`);
    const data = require('ml-dataset-iris');

    const features = data.getNumbers();
    let labels = data.getClasses();
    const classes = data.getDistinctClasses();

    const c = {};
    classes.forEach((v, idx) => c[v] = idx);
    labels = labels.map(l => c[l]);

    const cost = Array.from({length: COST_GRID_SIZE}).map(normalize(COST_GRID_SIZE, COST_MIN, COST_MAX)).map(pow10);
    const gamma = Array.from({length: GAMMA_GRID_SIZE}).map(normalize(GAMMA_GRID_SIZE, GAMMA_MIN, GAMMA_MAX)).map(pow10);

    const timeLabel = `iris-cv ${argv[0]}: `;
    console.time(timeLabel);
    for(let c of cost) {
        for(let g of gamma) {
            const svm = new SVM({
                quiet: true,
                cost: c,
                gamma: g
github mljs / libsvm / examples / probabilities.js View on Github external
function exec(SVM, precomputed) {
  const data = require('ml-dataset-iris');
  var trainData;

  const features = data.getNumbers();
  let labels = data.getClasses();
  const classes = data.getDistinctClasses();
  const c = {};
  classes.forEach((v, idx) => (c[v] = idx));
  labels = labels.map((l) => c[l]);

  if (precomputed) {
    const kernel = new Kernel('gaussian', { sigma: 1 / Math.sqrt(gamma) });
    trainData = kernel
      .compute(features)
      .addColumn(0, range(1, labels.length + 1));
  } else {
    trainData = features;
  }

  const svm = new SVM({
    quiet: true,
    cost: cost,
github mljs / libsvm / tools / iris.js View on Github external
'use strict';
const fs = require('fs');
const path = require('path');
const data = require('ml-dataset-iris').getDataset();
const distinctClasses = require('ml-dataset-iris').getDistinctClasses();
data.forEach(d => {
    d[4] = distinctClasses.indexOf(d[4]);
});
const str = data.map(d => d.join(' ')).join('\n');
fs.writeFileSync(path.resolve(__dirname, '../benchmark/data.txt'), str);
github mljs / libsvm / benchmark / iris / grid-search-benchmark.js View on Github external
function exec(SVM, time) {
    const MILISECONDS = time * 1000;
    const data = require('ml-dataset-iris');

    const features = data.getNumbers();
    let labels = data.getClasses();
    const classes = data.getDistinctClasses();

    const c = {};
    classes.forEach((v, idx) => (c[v] = idx));
    labels = labels.map(l => c[l]);

    const startTime = Date.now();
    let endTime = Date.now();
    let count = 0;
    while (endTime - startTime < MILISECONDS) {
        for (let c of cost) {
            for (let g of gamma) {
                const svm = new SVM({
                    quiet: true,
                    cost: c,
                    gamma: g
                });
github mljs / libsvm / examples / precomputed.js View on Github external
function exec(SVM, time, precomputed) {
  const MILISECONDS = time * 1000;
  const data = require('ml-dataset-iris');
  var trainData;

  const features = data.getNumbers();
  let labels = data.getClasses();
  const classes = data.getDistinctClasses();
  const c = {};
  classes.forEach((v, idx) => (c[v] = idx));
  labels = labels.map((l) => c[l]);


  let result;
  const t1 = Date.now();
  let t2 = Date.now();
  let count = 0;
  while (t2 - t1 < MILISECONDS) {
    if (precomputed) {
      const kernel = new Kernel('gaussian', { sigma: 1 / Math.sqrt(gamma) });
      trainData = kernel.compute(features).addColumn(0, range(1, labels.length + 1));
    } else {
      trainData = features;
    }
github mljs / libsvm / benchmark / iris / grid-search-benchmark-ml-svm.js View on Github external
function exec(time) {
    const MILISECONDS = time * 1000;
    const data = require('ml-dataset-iris');

    const features = data.getNumbers();
    let labels = data.getClasses();
    const classes = data.getDistinctClasses();

    const c = {};
    classes.forEach((v, idx) => (c[v] = idx));
    labels = labels.map(l => c[l]);

    const startTime = Date.now();
    let endTime = Date.now();
    let count = 0;
    while (endTime - startTime < MILISECONDS) {
        for (let c of cost) {
            for (let g of gamma) {
                const svm = new SVM({
                    C: c,
                    kernel: 'rbf',
                    kernelOptions: {
                        sigma: g

ml-dataset-iris

Iris flower data set

MIT
Latest version published 3 years ago

Package Health Score

46 / 100
Full package analysis

Similar packages