fabiochiu/medium-articles huggingface dataset:
Cervical Cancer Prognosis with Deep Learning
By: Tanvi Jain
Tags: Deep Learning, Machine Learning, Classification, Data Science, Healthcare Technology

Photo by National Cancer Institute on Unsplash

Healthcare diagnosis has a plethora of applications in machine learning, which are increasingly being used to support clinical decisions. Diseases can be detected by recognising patterns in diseases with patient records. To leverage the power of machine learning as a medical prognostic tool, I developed a risk classification model for Cervical Cancer through a public Risk Classification Dataset. If you too are a machine learning and biology enthusiast like me, then this article is the right place for you!

Cervical Cancer proliferates in the cervix endometrium (tissue) that is often correlated with socioeconomic lifestyle factors. Unfortunately, Cervical Cancer screening has various limitations, including danger of cells drying, poor quality, reporting problems, insufficient funding for screening programmes, and human errors. These limitations increase the scope of the role of Machine Learning to engender early-diagnosis, especially in non-developed or developing countries.

Instances of tumours that be classified as either malignant (cancerous) or benign (non-cancerous). Benign tumours do not spread and grow locally, thereby, not considered cancerous. However, they can still pose a danger, especially if they press against vital organs. Malignant tumours, in contrast, have the ability to spread and invade other tissues. This process, known as metastasis, is a key feature of cancer.

The cervical cancer data set used for this problem consists of 858 tumour samples where (65.5%) are benign tumours and 241 (34.5%) malignant tumours. Instances in the data set have the following attributes:

Cervical Cancer Attributes

An epidemiological overview of the attributes can be found in the description of the dataset.

We will now use the dataset to train four algorithms (decision tree, random forest, kNN, and MLP). They are good algorithms for supervised learning that can then be selected based on our metrics (explained further below) to identify the most accurate model.

Step 1: Setting up ML Project

We will begin by importing all the relevant libraries. Then we will set up the path using pandas. Further, we will define the variables as y (the output of diagnosis) and X (an array of all attributes). The code is shown below:

Step 2: DataSet Splitting

The dataset must be split into a training and testing set before getting started. As their names suggest, a training set is used to ‘train’ the algorithms and the testing set is used to measure the performance of the algorithm with unknown outcomes:

Train set (70%), for choosing and validating models Test set (30%), hold out data on which we will see how well models are able to generalise on unseen data.

Step 3: Defining the Metrics

Next, we need to define the key metrics to measure the efficiency of the models. The following four measurement metrics are used to evaluate the classifier’s performance:

Put what makes a good dataset
K-Nearest Neighbors Algorithm
By: Jason Wong
Tags: Supervised Learning, K Nearest Neighbours, Knn, Classification, Scikit Learn

The Manhattan distance is a pretty simple metric we can use to calculate distance. Take a look at the plot below, and imagine the grid is an overview map of city blocks. In order to get from point A to point B in the context of Manhattan distance, we couldn’t just go straight through the all the skyscrapers! We’d have to go n blocks east or west, and n blocks north or south.

Image by author

Manhattan distance differs from Euclidean distance when we calculate the difference between two points by using the absolute value of the difference. Back to the walking the blocks of Manhattan to get from point A to point B , if we were to go west first, we’d have a negative value. We still want this move to count so we take the absolute value of the difference. The formula for Manhattan distance:

The formula above states that the distance between point x and point y equals the sum of the absolute differences of the Y value subtracted from the X value in each dimension. We can also calculate the Manhattan distance using the Math module from Python. This time, instead of using the sqrt() function, we will use the abs() function.

Minkowski Distance

Hermann Minkowski, Public domain, via Wikimedia Commons

The Minkowski distance metric is a generalized distance across a normed vector space. A normed vector space, meaning a space where each point within has been run through a function. This distance metric is actually an induction of the Manhattan and Euclidean distances. The formula for Minkowski distance:

The formula above is similar to the Euclidean and Manhattan distance formulas but is just an exponent as the function. When c is set to 1, the formula is the same as Manhattan distance. When c is set to 2, it’s the same as Euclidean distance.
Multilable classification in sklearn
By: Rajan Lagah
Tags: Sklearn, Machine Learning, Classification

Multilable classification predict the multiple classes for the input. Like in image object detection you will have multiple objects that you want to identify. In simple classification you will predict number in MNIST data set ( example ) in this you will predict multiple numbers in image ( example )

Data

Data is from kaggle you can download it from here.

import pandas as pd train_df = pd.read_csv('./train_features.csv')

test_df = pd.read_csv('./test_features.csv')

y_train = pd.read_csv('./train_targets_scored.csv')

Then we will convert categorical variables to respective class codes.To do that we will first merge train and test data. So classes in both set get same corresponding categorical value.

grouped_df = pd.concat([train_df,test_df],axis=0)

grouped_df =grouped_df.drop(['sig_id'],axis=1)

converting

grouped_df['cp_type'] = grouped_df['cp_type'].astype('category')

grouped_df['cp_type'] = grouped_df['cp_type'].cat.codes grouped_df['cp_dose'] = grouped_df['cp_dose'].astype('category')

grouped_df['cp_dose'] = grouped_df['cp_dose'].cat.codes

Split train test set

x_train = grouped_df[:23814]

x_test = grouped_df[23814:]

y_train = y_train.drop(['sig_id'],axis=1)

not doing validation set because it just a simple example

Modeling

from sklearn.svm import LinearSVC

from sklearn.multiclass import OneVsRestClassifier svc = LinearSVC(max_iter=1500)

now come the new thing

OneVsRestClassifier :-

Now for each class it will build model for each class and it is trained as binary classification for that class. And in end it will predict 0 or 1 for each class .

clf = OneVsRestClassifier(svc)

clf.fit(x_train,y_train)

And we will have array of 0 and 1 and for every 1 we will output corresponding class to it.

Drawbacks:

As it create new model for each class so it will take huge amount of time to train the model
Naive Bayes Classifier -Why so “Naive”?
By: Bonny Dahal
Tags: Classification

Naïve Bayes Classifiers is a set of classification algorithm based on Bayes’ Theorem. It learns the probability of an object with certain features in a category through the training data and applies that to classify the test data. The method is called “naïve” because there is an assumption of independency and equal weights of each feature in the data. For example, to classify fruit as banana it takes the color, shape, and taste features of the fruit into consideration, assigns equal importance to each feature and assumes that no two features are in any way correlated to each other then classifies a yellow, long and sweet fruit as banana. It is mostly used for text or document classification because of its simplicity in training and classification purpose. This algorithm does the classification using the Bayes’ theorem.

Bayes’ Theorem which is also known as conditional theorem finds the probability of an event occurring given the probability of another event has already occurred.

Mathematically, Bayes’ Theorem is,

Basically, “A” is our target variable and “B” is our predictor variable. We are trying to find the probability of event A, given the event B is true. Event B is also known as evidence. For any classification problem Naïve Bayes gives the posterior probability which helps to decide whether to trust on the given prior probability. We will talk more about this later with a real example.

As per the data that we are using,

P(y|x) =(P(x|y)P(y))/P(x)

Let us consider IRIS dataset from UCI Machine Learning Repository for illustration of Naïve Classifier. For the data, the independent variables in the data are continuous in nature. While handling data of continuous nature, it is necessary to assume that the data is generated through a Gaussian process with “normal distribution”. Here, the continuous values of each variables are considered to be distributed in normal distribution. Hence, the conditional probability for this calculation is given by;

Let us look at the implementation of the Naïve Bayes Classifier in python:

After reading the data, let us move forward with the classification model.

So far, the classification looks great. Let’s look at the model’s accuracy.

The model has high accuracy in classifying the target variable.

Naive Bayes classification is simple and easy to calculate. However, the assumption of independent predictors is the main limitation of Naive Bayes because it is almost impossible to get a dataset in real life where the features are completely independent. Despite the limitation, we can find it being widely used for text classification, face recognition, news classification and so on.
Positive, Negative, or Neutral?
By: Sarah Mason
Tags: AI, Classification, NLP, Sentiment Analysis, Linguistics

Positive, Negative, or Neutral?

Photo by Tengyart on Unsplash

Communication is complex. There is written, verbal, and non-verbal. With technology, communication is very important in written form. We type more often than speaking to our devices. Using algorithms for classification and natural language processing, it is possible to score text on a scale to find sentiment. What is the value of sentiment? Sentiment is the tine of the selected piece of text. That shows positive, negative, or neutral in tone for applications in marketing, healthcare, and other domains.

How It Works

Sentiment Analysis is found by ranking. It is a logical operation of sorting terms and scoring by association to find cues to grammar to determine parts of each sentence. Afterwards, there is scoring on grouped words by trained algorithm to assign a score for finding how positive or negative a selected text is based on generated rules. This can be reused with a reliability on different texts to determine sentiment.

Classification and Ranking

There are apps and libraries for using and creating an automated sentiment toll, Python has Natural Language ToolKit (NLTK), Lexalytics has several apps for sentiment analysis. The demo is featured here using a press release about the covid19 vaccine and Walmart Clinics.

Grouping terms is classification to create rule based probability selecting themes from the text. The list is highest to lowest with “19 vaccine progress” the highest. It is interesting that this grouping does not include “covid”, but the number “19”. The rules select and group nouns and adjectives for assigning value on a scale to classify as a term based on evidence generated from the algorithm.

The picture shows the text, word cloud, and sentiment. This used the information to generate the “positive” sentiment showing anticipation and relief from a working covid-19 vaccine.

Following-Up

Sentiment analysis makes scoring a passage of text easier and faster with “smart technology”, Artificial Intelligence enabled analysis of text. Often, associated with responses and reviews, Sentiment Analysis can provide insert to pharmaceutical communications to gauge reaction for estimate of supply and demand. In the example, sentiment is positive for the covid-19 vaccine and that demand is likely to be high.
Avaliando a qualidade de um modelo de classificação binária
By: Fernanda Ribeiro
Tags: Ciencia De Dados, Classification Algorithms, Machine Learning, Classification, Inteligencia Artificial

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Step-By-Step Classification Modeling
By: Ulku Guneysu
Tags: Python, Programming, Machine Learning, Classification, Data Science

4. Model Check

Model prediction and residuals

The .predict method will provide model predictors:

y_hat_train = pipeline.predict(X_train) y_hat_test = pipeline.predict(X_test)

Residuals can be calculated by subtracting predictions from the original values, which are y_train and y_test .

Confusion matrix

To plot a confusion matrix, use the plot_confusion_matrix function from sklearn.metrics :

plot_confusion_matrix(pipeline, X_test, y_test, cmap=plt.cm.Blues)

It is a great way to visualize Actual Labels versus Predicted Labels.

Confusion matrix

Above, you can see a confusion matrix plot. By your classification model, the y-axis is True Labels and the x-axis is Predicted Labels. The target has 708 (673+35) values in 0-class and 126 (101+25) values in 1-class.

The box on the top left corner(673) represents the 0 values that are predicted correctly by the classification model. The box on the top right corner (35) represents the 0 values that are predicted incorrectly by the classification model. Your aim is to lower the number of incorrectly predicted values.

Classification report

Use the classification_report function from sklearn.metrics to create an evaluation metrics table. This table represents the quality of a model:

classification_report(y_test, y_test_pred)

Classification matrix

Precision measures how precise the predictors are:

Precision = Number of True Positives / Number of Predicted Positives

Recall indicates what percentage of the class is captured by the model:

Recall = Number of True Positives / Number of Actual Total Positives

F1-Score is the weighted average of Precision and Recall :

F1-Score = 2 * (Precision * Recall) / (Precision + Recall)

When checking for the quality of a model, it is imperative to decide which are evaluation metrics are more important for your dataset.

AUC Score and ROC Curve

AUC Score and ROC Curve are other evaluation metrics that provide information on the quality of the model:

If your model doesn’t have the decision_function property, you may try using the model.predict_proba function.

For the perfect ROC Curve, the area under the curve should be 1.0. The AUC value lies between 0.5 to 1, where 0.5 denotes a bad classifier and 1 denotes an excellent classifier.

ROC Curve

The graph above represents the ROC Curve for a classification model. It is obvious that the model is not doing very well. The goal is to get the AUC Score close to 1 and a ROC Curve with the max area (1.0) under the curve. An AUC Score around 0.5 is no better than predicting a random coin toss.

Feature importance

This evaluates the importance of the features in the classification model:
Bank Customer Analysis Using ANN
By: Samyak Kala
Tags: Deep Learning, Artificial Neural Network, Machine Learning, Classification, Data Science

The objective of this blog is to design a Deep Learning model i.e. an Artificial Neural Network Model to predict if customers of the bank will remain with a bank or if they will leave the bank and its services.

The dataset which we will be using is ChurnData.csv to perform statistical tests and predictive modeling consists of details of customers of a bank situated in the countries like France, Spain, and Germany. It consists of 10,000 rows and 14 columns.

Our target variable is a column named Exit which represents whether a customer has left the bank or not i.e (0 or 1).
Logistic Regression - An Intuitive Approach
By: Sharath H N
Tags: Regression, Ml Unravelled, Logistic Regression, Machine Learning, Classification

In the previous article, you have understood the math and the intuition behind Linear regression, a fundamental algorithm used for endless value prediction. To put it in a nutshell, you try to fit a line to a given set of points by minimizing the cost function. Now let us try to understand the intuition behind another fundamental but important algorithm called ‘Logistic Regression’. In this article, we’ll stress the similarities between Linear and Logistic Regression. Once you are comfortable with the idea of driving this algorithm, we can look into the math behind this.

Image Source: Google Image

When To Apply Logistic Regression?

To speak in novice terms, we apply this algorithm to solve a set of problems called the Classification Problems with a binary dependent variable. Let’s break down the terms, so that you can understand it clearly. A variable is said to be independent if the values it takes cannot be affected by any other parameters. The dependent variable is quite the opposite. The values, a dependent variable can take is influenced by numerous variables. If you have read Connect-Dots-with-Linear-Regression, you would’ve noticed that all the independent variables were represented using variable x and the dependent ones by y. Here, the binary dependent variable is a dependent variable which can take two different discrete values, generally but not always 0 and 1, meaning negative and positive values. We will follow the same conventions throughout the article and in the upcoming ones. Coming back to the classification problem, it is all about mathematically calculating all the possible discrete values of the dependent variable using the given set of independent variables. Though non-binary discrete dependent variables are also possible, we will restrict ourselves to binary variables for time-being.

Why The Word Regression?

There is a misunderstanding among the ML amateurs that regression stands for predicting continuous values and classification for discrete sets of values. But the actual meaning of the term is ‘To study the relationship between a set of independent variables and the dependent variable’, which perfectly makes sense. Even further, when we’ll look at the analytical part in the upcoming articles, you will see that the approach we use for both linear regression and logistic regression is quite similar and works on the same principle of minimizing the cost function.

Application

Some of the typical and classic problems that are solved using Logistic regression are:-

Tumor classification. Animal classification. Handwritten digit detection and classification.

If you stumble upon any other application, mention it in the comments.

So that’s all for this week. In the next one, we will dwell deep into the actual math behind the algorithm, its pros and cons. We’ll also try to walk you through an example if possible.

Stay Tuned!
How to deal with Class Imbalance
By: Jagandeep Singh
Tags: Data Science, Machine Learning, Classification

When dealing with a classification problem(binary or multiclass) if the total number of a class of data is far less than the total number of another class of data it is called a class imbalance. For example, you may have a 2-class problem with 100 instances(rows). A total of 80 instances are labeled with class 1 and the remaining 20 instances are labeled with class 2.

Some ways to deal with class imbalance are:

Upsampling

Upsampling means making copies of the minority class to handle class imbalance. As described in the figure below where the orange class is a minority and the class imbalance is handled by creating multiple copies of the orange class until it is equal to the blue class.

Downsampling

Downsampling is using randomly selected data points from the majority class to handle class imbalance. As shown in the figure below blue class is the majority and only randomly selected data points are used of the same amount as the orange class.

Adjusting Class weight

One of the simplest ways to deal with class imbalance is simply using the balance class weight argument in the algorithm. By default the class weights for logistic regression in sci-kit-learn is None, meaning that both classes will be given equal importance in tuning the model. Alternatively, you can pass 'balanced' in order to assign weights that are inversely proportional to that class's frequency.

lr_weighted = LogisticRegression(class_weight = ‘balanced’)

SMOTE creates more samples in the minority class, not by replicating the existing data points but by creating new points within the range of possibility. In other words, it creates new data points around the existing data.

SMOTE is generally a powerful way to deal with class imbalances, but it runs into computational issues when you have a large number of features due to the curse of dimensionality.
Winning Basketball
By: Sherwyn D Souza
Tags: Basketball, Logistic Regression, Machine Learning, Classification, Data Science

Dataset

The dataset ( games.csv ) contains information on 23,195 NBA games from every season between 2003–2019.

Sample of the dataset and its relevant features

This was randomly split into a train set (80% of data) to learn from, and a test set (20% of data) to evaluate performance. Further, this was split into X_train / X_test (features), and y_train / y_test (target).

Features

For each game (row), we have the following features (columns) for both home and away teams:

FG_PCT_home / FG_PCT_away : % of made shots (excluding free throws)

/ : % of made shots (excluding free throws) FT_PCT_home / FT_PCT_away : % of made free throws

/ : % of made free throws FG3_PCT_home / FG3_PCT_away : % of made 3-point shots

/ : % of made 3-point shots AST_home / AST_away : # of assists

/ : # of assists REB_home / REB_away : # of rebounds

I wanted to predict the HOME_TEAM_WINS column (target); assuming that ours is always the home team. A 0 represents a loss, and a 1 represents a win.

Dropped Games

The train set was missing data for 77 games. Estimating each feature of these games would detract from the analysis, so they were dropped. I also dropped one game with an erroneous 36–33 score.

Outliers

The following histograms display, for each feature, the count of values in a bin (value range). Most are centered, meaning there are no values far outside the middle that shift the distribution (potential outliers).
Deep learning losses for classification & probabilities
By: Alvaro Durán Tovar
Tags: Deep Learning, Pytorch, Loss Function, Classification, Probability

An unified view

Photo by Jan Antonin Kolar on Unsplash

Classification & Probability

Classification & Probability? Why mix both? Well, because classification indeed can be thought as fitting a probability distribution, bear with me. I’ll comment a bit about how to fit distributions and then relate it to classification.

Probability

The loss used for fitting a probability distribution is the negative log likelihood, I explain it with more detail here. What it does is given a distribution defined by some parameters (obtained from the output of a NN in this case), what is the probability of observing, (the target / label) Y? And then update the parameters through backpropagation in the direction where we maximize the probability of observing Y with a different set of parameters.

The observation Y won’t change obviously, as we want something that can fit as best as possible the generation of those observed Y (for future inference), we will change the parameters towards increasing the likelihood of obtaining those observations if sampling from the probability distribution.

One last time, we want a probability distribution parameterized from past data to predict some future data Y given some input X.

Each probability distribution have a different maximum likelihood estimation function, so I’m not going to enter into more detail here but we can reduce the general case to the following, where “p” is the maximum likelihood estimation function (I’m omitting the parameters of the distribution) (some examples gaussian, categorical, poisson…):

And we are lucky because deep learning frameworks already provides them!

Classification

Classification can be seen as using probability distributions, for the binary case we have the bernoulli distribution, for multi-class we have the categorical distribution, and you can think on the binary case as a special case of the multi-class classification.

If we have a probability distribution we know we can fit it with the negative log likelihood as mentioned above.

Also you probably already know we also have cross entropy and binary cross entropy. More weirds terms! Why?! :’(… Don’t worry, although cross entropy and NLL isn’t the same, for our case it’s the same (very well explained here), or better say the math formulas at the end simplify to the exact same thing, therefore cross entropy = binary cross entropy = NLL. They just exposes different apis, but they are the same at the end. Don’t you believe me? Take a look on the following code:

Why so many options for doing the same thing? Depending on the use case you want to use one or the other. Binary? Multi class? Logits? Normalized? …

Why negative on the “negative log likelihood”? Because the frameworks usually only implements miniziation, so we maximize the likelihood by minimizing the negative value.
Classification Fetal Health
By: Mohammed Almishal
Tags: Database, Machine Learning, Classification, Data Visualization, Data Science

Introduction

In this notebook I’ll Classify fetal health in order to prevent child and maternal mortality.

So, We will divide the result into 3 classes

Normal Suspect Pathological

Firstly I’ll explain what is the meaning of important feature:

baseline value — Baseline Fetal Heart Rate (FHR)

accelerations — Number of accelerations per second

fetal_movement — Number of fetal movements per second

uterine_con — Number of uterine contractions per second

light_decelerations — Number of LDs per second

severe_decel — Number of SDs per second

prolongued_decel — Number of PDs per second

abnormal_short — Percentage of time with abnormal short term variability

mean_value_of_sh — Mean value of short term variability

percentage_of_ti — Percentage of time with abnormal long term variability

let’s start import libraries.

Read data

describe data

missing data if there are some missing data that we have to fixed it

It seems there are no missing data

My target is fetal_health which has the result. So, we’ll analysis it and find the relationship between it and other feature.

remamber that 1.0 mean normal , 2.0 mean Suspect and 3.0 mean Pathological.

We will find the count of each status in this data, to easiest on us visualize it.

To more understand data we will find correlation between fetal health and other features.

Let’s see the distribution of the data and histogram

The data is varied in numbers, and this creates some problems for us. We will normalize the data to avoid these problems.

Let’s split the data into training data and test data. Let’s train the model on the training data and then test it on the test data.

0.8934169278996865

This ratio is in the Logistic Regression, Let’s try another model.
fastText for Text Classification
By: Shraddha Anala
Tags: Deep Learning, Machine Learning, Classification, NLP, Data Science

We will use the fastText classifier to classify the quality of questions asked on Stack Overflow. Download the dataset from here, if you are following along with this tutorial.

What is fastText?

fastText is an open-source library, developed by the Facebook AI Research lab. Its main focus is on achieving scalable solutions for the tasks of text classification and representation while processing large datasets quickly and accurately.

Photo by Marc Sendra Martorell on Unsplash

I highly recommend going through Facebook’s own blog post and research paper regarding the motivation behind fastText and to understand how it does what it’s developed to do.

According to their research, fastText stacks impressively in both accuracy and training and testing times against previously published state-of-the-art models.

It achieves this computational efficiency and accuracy by employing 2 methods to address classification and training word representations of text.

1. Hierarchical Softmax

A Softmax function is often used as an activation function to output the probability of a given input to belong to k classes in multi-class classification problems.

Hierarchical Softmax proves to be very efficient when there are a large number of categories and there is a class imbalance present in the data. Here, the classes are arranged in a tree distribution instead of a flat, list-like structure.

The construction of the hierarchical softmax layer is based on the Huffman coding tree, which uses shorter trees to represent more frequently occurring classes and longer trees for rarer, more infrequent classes.

The probability that a given text belongs to a class is explored via a depth-first search along the nodes across the different branches. Therefore, branches (or equivalently, classes) with low probability can be discarded away.

For data where there are a huge number of classes, this will result in a highly reduced order of complexity, thereby speeding up the classification process significantly compared to traditional models.

2. Word n-grams

Using only a bag of words representation of the text leaves out crucial sequential information. Taking word order into account will end up being computationally expensive for large datasets.

So as a happy medium, fastText incorporates a bag of n-grams representation along with word vectors to preserve some information about the surrounding words appearing near each word.

This representation is very useful for classification applications, as the contextual meaning of a couple of different words strung together also results in a particular sentiment echoed by that piece of text.
Huawei ML Kit -Genel Hatlarıyla Huawei Machine Learning Servisleri 2
By: Ubeyde Akgül
Tags: Detection, Segmentation, Hms, Machine Learning, Classification

Learn more. Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Make Medium yours. Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore
Quantum Advantage for Computer Scientists
By: Brian N. Siegelwax
Tags: IBM, Quantum Advantage, Quantum Computing, Classification, Quantum Supremacy

A Second Estimation Technique

In my article titled, “Benchmarking Quantum Advantage,” I wrote about a non-mathematical way to determine if your quantum algorithm can outperform its classical counterparts. TL;DR: notwithstanding queue times, quantum processors have a range of minimum-to-maximum runtimes; the classical algorithms need to at least be slower than these benchmarks. To impress anybody, they probably need to be much, much slower, but, again, you can initialize the maximum number of qubits and add a ridiculous amount of circuit depth and IBM Quantum, anyway, will give you the maximum runtime for any circuit run on that particular device. Simply compare that maximum runtime to the classical runtime.

This second technique is even simpler: it is the number 50.

In my article titled, “Maximum Quantum Classification,” I tried to really push the limits of the IBM Quantum simulator. TL;DR again: a circuit with 23 qubits and 51 Fredkin gates took 2 hours, 18 minutes, 5.9 seconds to run. A circuit with 24 qubits and 54 Fredkin gates resulted in a runtime error.

But, that’s just a free, online quantum computing simulator using 23 simulated qubits and using reset gates to simulate having more simulated qubits. It is estimated that the world’s most powerful supercomputers can only simulate quantum systems with up to around 50 qubits. Google’s “Quantum Supremacy” experiment used 53 qubits and fell just short of its goal. However, the consensus (outside Google) is that 54 or 55 qubits would’ve made the outcome indisputable.

Going back to my favorite quantum classification algorithm, I have read an estimate by MIT and Xanadu researchers that quantum advantage may be demonstratable at around 101 qubits, with 1 ancilla qubit being used to compare 2 50-qubit systems.

There is that number 50 again. And, if that isn’t enough, 50 Fredkin gates would be required.

Putting it all together, if your classical algorithm runs in less than a minute and your quantum algorithm uses five qubits, you can probably save yourself some time doing the calculations. If your classical algorithm, however, is slower than 200 seconds (using Google’s runtime) and your quantum state needs at least 50 qubits, I look forward to reading your paper!
Classification, Made Simple
By: Taylor Lucero
Tags: Learning And Development, Data, Machine Learning, Classification, Data Science

The Classification Breakdown

The exact steps of classification change depending on the data, algorithms, and parameters chosen, but there are a few generalized steps that most Classification models follow. The first step is always the Data Collection. The necessary information must be gathered towards the targeted feature and metrics through a method or database. To models, information gives the potential to bring insight to life but can be limited by the quality of the information gathered. The motto is “Garbage in, garbage out.”

Basic Steps of Classification

If the Data is already in its peak form, then there isn’t a need to perform any transformations to the set. The Optimum format for the Data depends on the quality and the intended use of the data. This could mean removing outliers, fixing errors, or even manipulating specific attributes’ structure to make it more understandable for the algorithm to read and analyze. For every issue, there is a likely transformation of best fit — techniques like Discretization, Normalization, Regularization, or Imputation. The third step is developing and training the model using an algorithm built upon a set of unique parameters to guide its training.

After the model is thoroughly trained, this model needs to be compared to a new set of data to see if it can provide accurate results. This would be the model’s testing phase, where it applies the learned information to a new set. With this step, we can see the accuracy of its training and identify issues that may not have been readily visible in the training phase. These issues could be from Overfitting and Underfitting to having insufficient data available for the model, but any of them could create incorrect estimations.

To fix these issues, we move into the fifth step, Evaluation, and Tuning. This step involves reducing any available errors and biases to an acceptable degree by fine-tuning the parameters relative to the model and algorithm used. However, don’t assume this is the last step; data science in of itself is an iterative and incremental process. To tune the model, one may need to return to any of the above steps.
Towards ML — Can you see the Forest for the Trees?
By: Karlo Leskovar
Tags: Random Forest, Python, Decision Tree, Machine Learning, Classification

Towards Machine Learning — Can you see the Forest for the Trees?

Last time we have covered some of the most important evaluation techniques for Machine Learning model. We could easily say that when someone blindly uses only accuracy as measurements, he really “can’t see the Forest for the Trees”. :) Joking aside, we saw that when the data is imbalanced, just accuracy is often not enough to properly evaluate the model.

As the title suggests, we are continuing our journey covering popular Machine Learning techniques. On todays topic, we have Decision Trees and Random Forests. As the later is an advanced version, or rather, a combination of multiple Decision Trees, I’ve decided to cover this two algorithms together.

With the article I will try to explain Decision Trees and Random Forest classifiers on a beginner level. Also, some interesting examples on real data are provided. After reading this, I hope you will be ready to deploy your own classifier.
Balancing The Imbalanced Datasets (SMOTE)
By: Shiva Charan Pabba
Tags: Imbalanced Data, Machine Learning, Smote, Classification, Resampling

Imbalanced datasets are common in real world. Handling these imbalances is a challenging task. For example, In a loan repayment prediction, Out of 100 cases there could be less than 20 defaulters. When this data is passed through any model to predict defaulters, accuracy will be very low as the data is biased towards non-defaulters.

To handle these kind of scenarios we can use resampling techniques. Following are few types of resampling techniques:

Over Sampling: The minority class values are increased to match with the count of majority class.

The minority class values are increased to match with the count of majority class. Under Sampling: The majority class values are decreased to match with the count of minority class.

The majority class values are decreased to match with the count of minority class. Combination of Over Sampling and Under Sampling: The majority class values are decreased and minority class values are increased simultaneously.

The increment or decrement mentioned above can further be done using different ways. Please go through this document to know more about different techniques.

In this article, we’ll try to understand the impact of Over sampling using KMeansSmote on this sample data — Loan data

Please go through this kaggle notebook where I performed basic EDA and model building.

The following diagram shows the distribution of loan status data (class in this case)

Classes are distributed in 3:1:1 ratio

When logistic regression and decision trees are applied to the given data, F1 score was 0.26 and 0.28 respectively. Let’s try to apply sampling methods to overcome this issue.

To perform Over Sampling techniques, the following library need to be installed.

pip install imbalanced-learn==0.6.2

From this library, we can import KMeansSmote as shown below:

from imblearn.over_sampling import KMeansSMOTE

We can apply the KMeansSmote as shown below:

#X is the entire dataset except the class(i.e. loan_status)

#y is the class column (loan_status)

X = df_model.drop([‘loan_status’],axis=1)

y = df_model[‘loan_status’] smote = KMeansSMOTE(sampling_strategy='auto') #X_sm and y_sm is the resampled data

X_sm, y_sm = smote.fit_sample(X, y)

When logistic regression and decision trees are applied to the resampled data, F1 score was increased to 0.72 and 0.74 respectively.

I hope this might have helped you with the basic understanding of the impact of oversampling technique. We can still improve the accuracy by hyperparameter tuning.

Please find the notebook here for reference— kaggle notebook

Feel free to comment below.

Thank you :)
Introduction to Meme Classification using PyTorch and fastText
By: Vibhav Sharma
Tags: Fasttext, Deep Learning, Memes, Pytorch, Classification

INTRODUCTION

Why Meme Classification?

Memes can be a great content to have a laugh or two. But a content which is hilarious to one can also be a loathe to another. Some people also deliberately create a meme whose salient purpose is to spread hate towards a community or a person.

Since the reach of content in social media is limited to no one. Reading memes is very common in the life of a college student. However, a lot of people are sharing distasteful memes and encouraging their ideas on social media sites. Such memes try to make fun of a target individual or group. Ideas and statements of such memes should be stopped before it is too late. A lot of students read such memes and may accept that idea is acceptable. Data Analyst from different part of the worlds are trying to solve the problem of identifying such memes.

Although the problem of Meme Classification can be Multiclass but for simplicity and to give you a glimpse of how to handle vision and language data we will be determining first whether the given meme is hateful or not?(Binary Classification)

Welcome to this field of enhancement 🐱‍🚀, Chronologically we have applied some of the best practiced techniques available at global platform for our research field.

Without any further delay lets see how we are going to approach this problem! ✌
Stepping up: Image Classification using TensorFlow 2.x and TensorFlow Dataset
By: Jan Bollenbacher
Tags: Neural Networks, Python, Machine Learning, Classification, TensorFlow

In this tutorial, we will build a network to predict the class of an image. Therefore we use the tf_flowers dataset, which consists of 3,670 and 5 different classes. This tutorial builds upon a tutorial by TensorFlow.

This tutorial follows our well-known workflow:

Loading the data and preparing our datasets Define the model Training and evaluating the model

Loading the data and preparing our datasets

First, let's have a look at our dataset. We are using the tf_flowers dataset provided by the TensorFlow Dataset library (tfds).

We, therefore, load the dataset in our get_dataset() function using tfds. After that, we apply a preprocessing function on each sample in the dataset and generate a batch of size one.

In the main() function, we plot the first 9 images in the dataset. The result should be something like this:

The first 9 images in our dataset. As you can see, the three images in row three belong to the class dandelion. They differ very much from the dandelion in the second row.

There are a few problems in our dataset:

the different sizes of the images, the range of the pixels are from 0 to 255 (we prefer them between 0 and 1), and the encoding of the image labels.

To solve these problems, we apply a resize on the images, standardize them by dividing them by 255, and encode the labels using the one-hot() function. One-hot encoding means that instead of one scalar value, we represent our classes by vectors. Every row in the vector represents one class. We want to classify 5 classes, so label 4 becomes [0 0 0 1 0]. Also, we split the data into train and test data and shuffle them.

As you can see, we added parameters to specify batch size, image width, and image height.

This leaves us with the following output:

The pixels' value in the images is between 0 and 1, imshow() plots float values.

Define the Model

As in the tutorials before, we define our model as a class and inherit from tf.keras.Model. We define 3 Convolutional Layer, each with a Max Pooling Layer after that a Flatten Layer and a Dense Layer.

We combine and train the model using our trainer_cnn.py and main.py (see Appendix):

As you can see, the training and validation accuracy rises first. After a couple of epochs, the accuracy doesn’t rise anymore and starts decaying.

This effect is due to overfitting. Each epoch, the model learns using all available data points. After a few epochs, the model remembers the training data. We can augment our data to overcome this issue: we use our existing images and generate new images by zooming or rotating the images.

Therefore we apply augmentation and add a dropout layer to our model. Both layers are just active in training time:

After training, we get a much better validation accuracy, and both losses are dropping:
Generative vs Discriminative Classifiers in Machine Learning
By: Soner Yıldırım
Tags: Artificial Intelligence, Predictive Analytics, Machine Learning, Classification, Data Science

Generative classifiers

Consider a case where we have a feature x and a target variable y. We are trying to predict y based on the values of x.

Generative classifiers learn the joint probability distribution P(x,y). The focus is on how features and target variable occur together. The goal is to be able to explain how the data is generated.

Once the model captures the process that generated the data, it can make predictions on the new examples (i.e. data points). Thus, the key factor for generative classifiers is to be able to learn the underlying data distribution.

In order to make predictions, generative classifiers transform the joint probability ( P(x,y) ) to a conditional probability ( P(y|x) ) by using the Bayes rule. If you are not familiar with the notation, P(y|x) means probability of y given the values of x.

Naive bayes classifiers and hidden markov models are examples of generative classifiers.

Let’s say we have some points that belong to either blue or orange class. These points are plotted in the figure below. The joint probability distributions based on the known values of x and y (training data) are also shown in the figure.

(image by author)

The labels of new data points are decided based on the joint probability distributions. For instance, the green point in the figure above is labelled as orange.

Since generative models learn the data distribution, they can also be used to generate new data.
Imbalanced Data and how to proceed?
By: Akhil Kanike
Tags: Imbalanced Data, Machine Learning, Naive Bayes Classifier, Classification, Performance Metrics

Let’s take credit card data from Kaggle for our understanding in real world. https://www.kaggle.com/mlg-ulb/creditcardfraud. Please go through the link to understand about the data.

Lets plot the data and see how it looks: (For detailed code go to https://www.kaggle.com/mlg-ulb/creditcardfraud)

Example got 284315 class 0 records and 492 class 1 records. Majority class is 0, Minority class is 1.

Feeding the unbalanced data without to Gaussian Naïve Bayes and lets see the confusion matrix:

The accuracy is 0.9783292604140333

The precision is 0.06280788177339902

The recall is 0.8292682926829268

The F1-Score is 0.11677160847166573

Never fall prey to high accuracy of 97% and proceed. Check other performance metrics as well. Precision equals 0.0628. It has correctly predicted only 204 times out of 3248 Fraud-Predicted ones(3248+204 ). You need to think now. Recall is 204 Fraud-Predicts out of 246 Actual-Frauds (42+204), which equals 0.829.

Precision is very low, so cannot proceed further with this data. So let’s try to balance and retry. How to balance?

There are many resampling methods like — over-sampling, under-sampling, combination of both and many more to balance.

Here I’m resampling with SMOTEENN, a combined method of over and under-sampling from imblearn.combine package and plotted the data.

We got 284315 1’s and 283870 0’s. Applied Gaussian Naïve Bayes and let’s check the confusion matrix.

The accuracy is 0.9151369445920878

The precision is 0.9732570164257713

The recall is 0.8538964692643128

The F1-Score is 0.9096780719533348

As you can see, precision is improved as we proceeded with the balanced the data.

In the below tab I’m posting the code used to get all these results.

Please comment if you want me to improve on anything.

References:

https://scikit-learn.org/stable/modules/naive_bayes.html
Super easy Python iris classification (using XGBoost) Machine learning
Tags: Python, Machine Learning, Classification, Xgboost, Iris

XGBoost Documentation - xgboost 1.3.0-SNAPSHOT documentation

XGBoost is an optimized distributed gradient boosting library designed to be highly efficient, flexible and portable…