I’m excited to announce Kalimdor.js, a Typescript based Machine Learning library and very similar to ScikitLearn, that runs directly on the browsers and Node.js environment. In fact, many APIs are direct translations from ScikitLearn and rewritten into Typescript.

Using the library, Javascript developers can compete in Kaggle competitions as equally as the Python developers!

Why Machine Learning in Typescript and Browsers?

Spotify music recommendation system operating offline, source

Kalimdor.js is primarily written in Typescript, which is a strongly typed programming language that can drastically improve your development experience by providing compilation level type checks.

Browser-based Machine Learning can be useful in many different scenarios. Imagine you have a music recommendation system on your React Native application. You are working on a scenario when the user completely loses their Internet connection, the recommendation system must continue working regardless of the wifi status, then Kalimdor can still suggest new music to you without needing to talk to the server, no matter if you’re at home, in the office, or on that internet-free, sweaty train.

Why another Machine Learning Library?

Machine Learning in Javascript, source

Kalimdor features supervised and unsupervised models including Decision Tree, Random Forest, PCA, KMeans and SVM. There are many Machine Learning algorithms that are individually written in the NPM ecosystem, but none exists that package them all into one.

In the field of Javascript, it is clear that Deep Learning is the preeminent usage of Machine Learning, although not every problem requires it!

TensorFlow is a powerful library that’s mostly used for deep learning, although its computational model based on directed graphs certainly allows for a wider range of use cases. Deep learning is the main area of machine learning where scikit-learn is really not that useful. For most practical machine learning tasks, TensorFlow is overkill. Scikit-learn is a much more user-friendly library that is more than sufficient in most scenarios.

Regardless of what I mentioned above, the library can be a great companion to any JS Deep Leaning libraries such as Tensorflow.js or Brain.js since it supports utilities including train_test_split, confusion_matrix, and KFold.

This article will show you how to install the library and solve a popular Machine Learning problem from Kaggle, right on your browser.

Why Kalimdor?

The name originates from World of Warcraft, a game that I have been playing. There is an area in WoW called Kalimdor, which has a lot of natural environments featuring forests. Since Tree is my favourite algorithm in Machine Learning, I chose the name Kalimdor, the land of forests.

Installation

Set up a Node.js environment and install Kalimdor.js

# using Yarn

$ yarn add kalimdor -save

# using NPM

$ npm install kalimdor -save-dev

Titanic: Machine Learning from Disaster

Description

The sinking of RMS Titanic is one of the most tragedic shipwrecks in history, which has taken the lives of 1502 out of 2224 passengers on April 15, 1912.

One of the reasons the incident led to such loss of life is there were lack of lifeboats available and the survivability dependent on their luck.

This section of the article will be training a RandomForest model to predict whether each passenger has survived or not.

Solving this problem will help you practice following skills

Binary classification

RandomForestClassifier basics

Nice intro, let’s code it

Importing the packages

You can download the JSON files from below links:

2. Preprocessing data (Feature Engineering)

The dataset is not directly suitable for training unless we preprocess it. In this step, we will take any string, boolean or number with too large values and turn them into meaningful values for the Machine Learning model ;)

Utilities for dealing with the title, age, fare and embarked

Feel free to refactor it ;)

Training the model with Kalimdor’s RandomForestClassifier model

Simple and straightforward; you can save the training state using cls.toJSON()

There are many ways to improve the accuracy score, perhaps using a different model such as XGBoost, a boosting algorithm, or improving the feature engineering code.

In conclusion, Kalimdor.js is still a growing library, and it is a great joy building the library since I can provide the world with an amazing library and at the same time solidify my Machine Learning knowledge. If you’d like to join this journey with me head over the project Github repository and check out the documentation site. Follow up articles will explore more Kaggle challenges using Kalimdor.js.