MITB Banner

Complete Guide To QLattice: A New And Transparent Machine Learning Framework

In this article, we will learn about the following in detail:- Introduction to Qlattice How to implement Qlattice
Share

Machine learning techniques and algorithms have time and again proven to be really effective over the past few years and there are more breakthroughs that will come in the near future. But most of the algorithms at hand use a lot of statistical methods and require a lot of human intervention. To reduce the amount of human interaction, a new machine learning algorithm was developed called QLattice. 

In this article, we will learn about the following in detail:-

  1. Introduction to Qlattice
  2. How to implement Qlattice

Introduction to QLattice

Qlattice has its advantages over neural networks and decision trees. It removes the concept of black box seen in neural networks and serves explainability similar to that of a decision tree. It was developed by a research startup named abzu earlier this year. 

Qlattice works by searching through thousands of potential models and finds one with the right features and interactions to fit as the perfect model for the problem. 

Initially, the user has to set a few parameters like the input features, target and the independent variables. QLattice works with supervised learning and the input features and target are called registers. These registers form the entry and exit points for the QLattice model. Once the registers are set, a collection of possible models can be extracted from the QLattice. This collection of models corresponds to something called QGraphs. These graphs are a set of nodes and edges where the nodes have activation functions and edges carry weights. This indicates that upon training a Qgraph, it extracts essential information from the features to predict the target. 

Qlattice

Implementation of QLattice

Let us understand the working of QLattice better by implementing a simple classification model. Before we begin, please make sure you have created an account in the abzu website. You will receive access to it and be directed to the dashboard. 

qlattice

Here, you can either use the playground they provide or use Colab. I have made use of Colab. 

For implementing this we need the Feyn library which is the software development kit that we use to interact with the QLattice.

To install the Feyn library use the command

pip install feyn

The dataset

To keep things simple I have used the diabetes dataset which is downloaded from Kaggle. Let us load the dataset and import the needed libraries

from google.colab import drive
import feyn
import numpy as np
import pandas as pd
drive.mount('/content/gdrive/')
dataset=pd.read_csv('/content/gdrive/My Drive/diabetes/diabetes.csv')
dataset.head()

 Splitting the dataset 

Before we split the dataset let us assign our target value to a variable named target. Next, we will split the dataset into train and test set.

target='Outcome'
train, test = train_test_split(dataset, test_size=0.4, random_state=42, stratify=dataset[target])

Qgraph

Qgraphs are produced by Qlattice which forms a graphical structure that connects the input to output. We need to give instructions about the features of this. To be able to access this since it belongs to the third party we need a URL and authorization token. This is made available in your abzu dashboard. 

qlattice = feyn.QLattice(url="the url", api_token="token")

Note here in the qgraph we are just giving the basic information and not specifying which algorithm to use. 

qgraph = qlattice.get_classifier(train.columns, target, max_depth=3)
qgraph.head(2)
qgraph

As you see for each feature automatically the nodes with algorithms and activation function are assigned. Green boxes represent the inputs and outputs, white boxed with pink border represent interactions. Interactions take in input as values, builds a function for that value and predicts the outcome. It is similar to the neural network but we can see exactly what is happening in each column. Here the classification algorithm seems to be gaussian. 

Training

Let us begin to train the qgraph over 5 fittings. Here epochs are called fittings. The code below shows the training loop.

depth = 5
loss_function = feyn.losses.squared_error
nloops = 5
for loop in range(nloops):
    qgraph.fit(train, loss_function=loss_function, threads=4,show='graph')
    qlattice.update(qgraph.best())
qgraph

Below, it shows the best loss value after 5 fittings, here the loss value is 0.152 which is a good loss value. 

Once training is done it is time to move to predictions. 

Predictions

output_graph = qgraph.sort(train)[0]
df_pred = valid.copy()
df_pred['predicted'] = output_graph.predict(valid) 
threshold = 0.5
y_pred = np.where(df_pred.predicted > threshold, True, False)
y_real = df_pred[target].astype(bool)
plt.figure(figsize=(8, 5))
feyn.plots.plot_confusion_matrix(y_real, y_pred)
confusion matrix
train_pred = output_graph.predict(train)
print('Overall training accuracy: %.4f' %np.mean(np.round(train_pred) == train[target]))
print('Overall validation accuracy: %.4f' %np.mean(y_pred == y_real))

The above code and confusion matrix shows that the model performs well because we have not performed any pre-processing and not specified the type of algorithm. Qgraph learnt and trained on only the best model for the dataset. 

Conclusion

In the article, we learnt about the new machine learning model called Qlattice and implemented it on a simple classification dataset and got good results. 

PS: The story was written using a keyboard.
Share
Picture of Bhoomika Madhukar

Bhoomika Madhukar

I am an aspiring data scientist with a passion for teaching. I am a computer science graduate from Dayananda Sagar Institute. I have experience in building models in deep learning and reinforcement learning. My goal is to use AI in the field of education to make learning meaningful for everyone.
Related Posts

CORPORATE TRAINING PROGRAMS ON GENERATIVE AI

Generative AI Skilling for Enterprises

Our customized corporate training program on Generative AI provides a unique opportunity to empower, retain, and advance your talent.

Upcoming Large format Conference

May 30 and 31, 2024 | 📍 Bangalore, India

Download the easiest way to
stay informed

Subscribe to The Belamy: Our Weekly Newsletter

Biggest AI stories, delivered to your inbox every week.

AI Courses & Careers

Become a Certified Generative AI Engineer

AI Forum for India

Our Discord Community for AI Ecosystem, In collaboration with NVIDIA. 

Flagship Events

Rising 2024 | DE&I in Tech Summit

April 4 and 5, 2024 | 📍 Hilton Convention Center, Manyata Tech Park, Bangalore

MachineCon GCC Summit 2024

June 28 2024 | 📍Bangalore, India

MachineCon USA 2024

26 July 2024 | 583 Park Avenue, New York

Cypher India 2024

September 25-27, 2024 | 📍Bangalore, India

Cypher USA 2024

Nov 21-22 2024 | 📍Santa Clara Convention Center, California, USA

Data Engineering Summit 2024

May 30 and 31, 2024 | 📍 Bangalore, India