Giter Site home page Giter Site logo

karyarayajasa / machine_learning Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ekojs/machine_learning

0.0 2.0 1.0 14 KB

Berisi kumpulan algoritma dari Machine Learning dan Computational Intelligance

License: MIT License

JavaScript 100.00%

machine_learning's Introduction

Machine Learning & Computational Intelligence

Berisi kumpulan algoritma dari Machine Learning dan Computational Intelligance

1. K-Means Clustering Algorithm

Contoh menggunakan nodejs console :

var ejs_kmeans = require('./unsupervised/ejs_kmeans');
function TestData(samples,centroid){
	console.log('Samples Data : %s \n','('+samples.join(') (')+')');
	var k_means = new ejs_kmeans.k_mean_cluster(samples);
	k_means.initialize(centroid);
	k_means.calculate();
	console.log(k_means.result().replace(/<br \/>/g,"\n").replace(/&nbsp;/g,' ').replace(/<\/?strong>/g,''));
}

TestData([[5.09,5.80], [3.24,5.90], [1.68,4.90], [1.00,3.17], [1.48,1.38], [2.91,0.20], [4.76,0.10], [6.32,1.10], [7.00,2.83], [6.52,4.62]],[[1.48,1.38],[4.76,0.10]]);
//TestData([[5.09,5.80], [3.24,5.90], [1.68,4.90], [1.00,3.17], [1.48,1.38], [2.91,0.20], [4.76,0.10], [6.32,1.10], [7.00,2.83], [6.52,4.62]],[[5.09,5.80], [3.24,5.90]]);
//TestData([[1.0,1.0],[1.5,2.0],[3.0,4.0],[5.0,7.0],[3.5,5.0],[4.5,5.0],[3.5,4.5]],[[1,1],[5,7]]);
//TestData([[1,1],[2,1],[4,3],[5,4]],[[1,1],[2,1]]);
//TestData([[1,1,2],[2,1,3],[4,3,2],[5,4,4],[4,4,4]],[[1,1,2],[2,1,3]]);
//TestData([[5.09,5.80], [3.24,5.90], [1.68,4.90], [1.00,3.17], [1.48,1.38], [2.91,0.20], [4.76,0.10], [6.32,1.10], [7.00,2.83], [6.52,4.62]],[[5.09,5.80], [3.24,5.90], [1.68,4.90]]);

Baca artikel pada K-Means Clustering Algorithm

Simulasi program di sini

2. Backpropagation Neural Network

Penggunaan Backpropagation disini, penulis masih menggunakan fungsi aktivasi secara hardcode, fungsi aktivasi pada IH menggunakan TANH sedangkan pada HO menggunakan fungsi aktivasi SOFTMAX dan 'SIGMOID` untuk Binary Classification.

Contoh menggunakan nodejs console :

var ejs_neural = require('./supervised/ejs_neural');
var opt = {
	learning_rate:0.05,
	momentum:0.01,
	maxEpochs:500
};
// var TT = [[-1,-1,1,-1],[-1,1,1,1],[1,-1,1,1],[1,1,1,-1]]; // xor
// var TT = [[-1,-1,1,-1],[-1,1,1,-1],[1,-1,1,-1],[1,1,1,1]]; // and
var TT = [[-1,-1,1,-1],[-1,1,1,1],[1,-1,1,1],[1,1,1,1]]; // or
// var json = '{"0":-1.8570453538530167,"1":-1.0578781246699556,"2":1.6716922611300928,"3":-1.1001127357871128,"4":1.8538154659419666,"5":-1.124630964477959,"6":-1.677438527019374,"7":-1.0075326202144037,"8":-1.0230813212370369,"9":0.46272458742612566,"10":-0.6512284898272416,"11":-0.6612252388250472,"12":-0.9230821882924356,"13":0.7306611846866936,"14":-1.066699519330741,"15":-0.5033335760896673,"16":3.412458805650443,"17":1.6494378062956072,"18":3.3143332296912598,"19":-1.6840062015951618,"20":0.2616096437809812}';
var nn = new ejs_neural.Neural(3,4,1,opt);
// tes.fromJSON(json);
// nn.initWeights(ejs_neural.range(0.01,3*4+4+4*1+1,0.01))
nn.train(TT);
// var data = nn.makeTrainTest(TT);
// console.log(data);
// console.log('Mulai training ...');
// nn.train(data.data_training);
// console.log('Training selesai ...');
// console.log('--------------- Final nn weights -----------------');
// console.log(nn.toJSON());
// console.log('--------------------------------------------------');
// console.log('Akurasi data training : %d',nn.accuracy(data.data_training));
// console.log('Akurasi data test : %d',nn.accuracy(data.data_test));
console.log('Akurasi data : %d',nn.accuracy(TT));

console.log('Actual %d, prediction : %d',-1,nn.forward([-1,-1,1]).outputs[0]); // -1 or
console.log('Actual %d, prediction : %d',1,nn.forward([1,1,1]).outputs[0]); // 1 or
console.log('Actual %d, prediction : %d',1,nn.forward([-1,1,1]).outputs[0]); // 1 or
console.log('Actual %d, prediction : %d',1,nn.forward([1,-1,1]).outputs[0]); // 1 or

machine_learning's People

Contributors

ekojs avatar

Watchers

 avatar  avatar

Forkers

juaan

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.