Giter Club home page Giter Club logo

knn-js's Introduction

knn-js

  • Clickable/Interactive k-NN algorithm in javascript
  • It can be integrated into a web application
  • It is based on d3

demo

Setup

Include the libraries

<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="../dist/knnjs.min.js"></script>
<link rel="stylesheet" href="../dist/knnjs.min.css" />

CDN - UNPKG

<script type="text/javascript" src="https://unpkg.com/[email protected]/dist/knnjs.min.js"></script>
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/knnjs.min.css" />  

Usage

Hello World example

Create an element to hold the table

<div id="myknn"></div>

Turn the div element into a d3 scatter chart with some simple javascript

var myknn = knnjs.knn();
myknn.init(document.getElementById("myknn"), {
  selectedDataSet: [
    {age: 37, year_of_operation: 63, positive_axillary_nodes: 0, survival_status: 1},
    {age: 43, year_of_operation: 58, positive_axillary_nodes: 52, survival_status: 2},
    {age: 43, year_of_operation: 59, positive_axillary_nodes: 2, survival_status: 2},
    {age: 43, year_of_operation: 63, positive_axillary_nodes: 14, survival_status: 1},
    {age: 43, year_of_operation: 64, positive_axillary_nodes: 2, survival_status: 1},
    {age: 46, year_of_operation: 65, positive_axillary_nodes: 20, survival_status: 2},
    {age: 48, year_of_operation: 66, positive_axillary_nodes: 0, survival_status: 1},
    {age: 50, year_of_operation: 61, positive_axillary_nodes: 0, survival_status: 1},
    {age: 54, year_of_operation: 62, positive_axillary_nodes: 0, survival_status: 1},
    {age: 58, year_of_operation: 61, positive_axillary_nodes: 2, survival_status: 1}
  ], 
  colorMap: {
    "1": "#EE7733",
    "2": "#0077BB"
  },
  selectedColumns: ["age", "year_of_operation"], 
  categoryName: "survival_status"
});

hello

Take a look at examples/hello.html for more information

Work with the chart table

Include the libraries

<script src="https://d3js.org/d3.v4.min.js"></script>
<script src="../dist/knnjs.min.js"></script>
<script src="../dist/charttable.min.js"></script>
<link rel="stylesheet" href="../dist/knnjs.min.css"></link>
<link rel="stylesheet" href="../dist/charttable.min.css"></link>

Create div elements to hold the table

<div id="mytable"></div>
<div id="myknn"></div>

Work with chart table

const mytable = charttable.table();
const myknn = knnjs.knn();
const tol_vibrant = ["#EE7733", "#0077BB", "#33BBEE", "#EE3377", "#CC3311", "#009988"];
mytable.initTbl(document.getElementById("mytable"), {
  colors: tol_vibrant,
  minSelectedRow2Show: 4,
  minSelectedCol2Show: 2,
  height: 540,
  onSelect: function(data) {
    myknn.init(document.getElementById("myknn"), {
      colorMap: data.selectedColorMap,
      selectedDataSet: data.selectedRows, 
      selectedColumns: data.selectedColumns, 
      categoryName: data.categoryName
    });
  }
});

mytable.showDataset([
  {age: 30, year_of_operation: 65, positive_axillary_nodes: 0, survival_status: 1},
  {age: 38, year_of_operation: 66, positive_axillary_nodes: 0, survival_status: 1},
  {age: 42, year_of_operation: 59, positive_axillary_nodes: 0, survival_status: 2},
  {age: 49, year_of_operation: 63, positive_axillary_nodes: 0, survival_status: 2},
  {age: 49, year_of_operation: 61, positive_axillary_nodes: 0, survival_status: 1},
  {age: 55, year_of_operation: 66, positive_axillary_nodes: 18, survival_status: 1},
  {age: 56, year_of_operation: 60, positive_axillary_nodes: 0, survival_status: 1},
  {age: 61, year_of_operation: 65, positive_axillary_nodes: 0, survival_status: 2},
  {age: 61, year_of_operation: 59, positive_axillary_nodes: 0, survival_status: 1},
  {age: 64, year_of_operation: 66, positive_axillary_nodes: 0, survival_status: 1}
]);

charttable

TODO

  • use webpack to build

knn-js's People

Contributors

hemingwaylee avatar

Stargazers

Emineh_GhT avatar Sajjad Aemmi avatar Majid Hojati avatar

Watchers

 avatar

Forkers

apachesep

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.