Trending December 2023 # Clarifying Image Recognition Vs. Classification In 2023 # Suggested January 2024 # Top 21 Popular

You are reading the article Clarifying Image Recognition Vs. Classification In 2023 updated in December 2023 on the website We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Clarifying Image Recognition Vs. Classification In 2023

In this article, we’ll delve deep into image recognition and image classification, highlighting their differences and how they relate to each other. By understanding these concepts, you’ll be better equipped to leverage their potential in various areas of your business.

Image recognition: Turning pixels into meaningful information What is image recognition?

Image recognition is the process of analyzing images or video clips to identify and detect visual features such as objects, people, and places. This is achieved by using sophisticated algorithms and models that analyze and compare the visual data against a database of pre-existing patterns and features.

 Image recognition is a complex and multi-disciplinary field that combines computer vision, artificial intelligence, and machine learning techniques to perform tasks such as facial recognition, object detection, and scene analysis.

Image recognition can be used in the field of security to identify individuals from a database of known faces in real time, allowing for enhanced surveillance and monitoring. It can also be used in the field of healthcare to detect early signs of diseases from medical images, such as CT scans or MRIs, and assist doctors in making a more accurate diagnosis.

Source: GitHub

Image classification: Sorting images into categories What is image classification?

Image classification is a subfield of image recognition that involves categorizing images into pre-defined classes or categories. In other words, it is the process of assigning labels or tags to images based on their content. Image classification is a fundamental task in computer vision, and it is often used in applications such as object recognition, image search, and content-based image retrieval.

A sector where image classification is commonly used is e-commerce. It’s used to classify product images into different categories, such as clothing, electronics, and home appliances, making it easier for customers to find what they are looking for. It can also be used in the field of self-driving cars to identify and classify different types of objects, such as pedestrians, traffic signs, and other vehicles.

Image recognition vs. Image classification: Main differences

While image recognition and image classification are related, they have notable differences that make them suitable for distinct applications.

1. Object detection vs. categorization

Image recognition focuses on identifying and locating specific objects or patterns within an image, whereas image classification assigns an image to a category based on its content. In essence, image recognition is about detecting objects, while image classification is about categorizing images.

2. Use cases and applications

Image recognition is ideal for applications requiring the identification and localization of objects, such as autonomous vehicles, security systems, and facial recognition. Image classification, however, is more suitable for tasks that involve sorting images into categories, like organizing photos, diagnosing medical conditions from images, or analyzing satellite images.

3. Complexity and processing time

Image recognition is generally more complex than image classification, as it involves detecting multiple objects and their locations within an image. This can lead to increased processing time and computational requirements. Image classification, on the other hand, focuses solely on assigning images to categories, making it a simpler and often faster process.

Table 1. Main difference How image recognition and image classification are related?

Despite their differences, image recognition and image classification share some common ground:

1. Techniques and technologies

Both processes use similar techniques and technologies, such as machine learning algorithms and deep learning models like convolutional neural networks (CNNs). These methods can be adapted for either image recognition or classification tasks, depending on the specific application.

2. Interdependence in applications

In some applications, image recognition and image classification are combined to achieve more sophisticated results.

For instance, an autonomous vehicle may use image recognition to detect and locate pedestrians, traffic signs, and other vehicles and then use image classification to categorize these detected objects. This combination of techniques allows for a more comprehensive understanding of the vehicle’s surroundings, enhancing its ability to navigate safely.

3. Feature extraction and analysis

Both image recognition and image classification involve the extraction and analysis of image features. These features, such as edges, textures, and colors, help the algorithms differentiate between objects and categories.

In both cases, the quality of the images and the relevance of the features extracted are crucial for accurate results.

Real-world applications of image recognition and classification

To further clarify the differences and relationships between image recognition and image classification, let’s explore some real-world applications.

1. Medical imaging

Medical imaging is a popular field where both image recognition and classification have significant applications. Image recognition is used to detect and localize specific structures, abnormalities, or features within medical images, such as X-rays, MRIs, or CT scans. This helps medical professionals diagnose and treat various conditions.

Image classification, on the other hand, can be used to categorize medical images based on the presence or absence of specific features or conditions, aiding in the screening and diagnosis process. For instance, an automated image classification system can separate medical images with cancerous matter from ones without any.

To learn more about AI-powered medical imagining, check out this quick read.

2. Security

Image recognition and classification are critical tools in the security industry that enable the detection and tracking of potential threats. Automated image recognition solutions match real-time surveillance images with pre-existing data to identify individuals of interest, while image classification solutions categorize and tag objects in surveillance footage. 

Facial recognition is a specific form of image recognition that helps identify individuals in public areas and secure areas. These tools provide improved situational awareness and enable fast responses to security incidents.

If you wish to learn more about the use cases of computer vision in the security sector, check out this article.

3.  Environmental monitoring

Environmental monitoring and analysis often involve the use of satellite imagery, where both image recognition and classification can provide valuable insights. Image recognition can be used to detect and locate specific features, such as deforestation, water bodies, or urban development. 

Image classification, meanwhile, can be employed to categorize land cover types or identify areas affected by natural disasters or climate change. This information is crucial for decision-making, resource management, and environmental conservation efforts.

Watch this video to learn more about the marriage of satellite imaging and AI-powered image recognition/classification:

To learn more, check out these articles on:


While image recognition and image classification are related and often use similar techniques, they serve different purposes and have distinct applications. Understanding the differences between these two processes is essential for harnessing their potential in various areas. By leveraging the capabilities of image recognition and classification, businesses and organizations can gain valuable insights, improve efficiency, and make more informed decisions.

Further reading

If you need help finding a vendor or have any questions, feel free to contact us:

Shehmir Javaid

Shehmir Javaid is an industry analyst at AIMultiple. He has a background in logistics and supply chain management research and loves learning about innovative technology and sustainability. He completed his MSc in logistics and operations management from Cardiff University UK and Bachelor’s in international business administration From Cardiff Metropolitan University UK.





You're reading Clarifying Image Recognition Vs. Classification In 2023

Image Annotation In 2023: Definition, Importance & Techniques

Image annotation is one of the most important stages in the development of computer vision and image recognition applications, which involves recognizing, obtaining, describing, and interpreting results from digital images or videos. Computer vision is widely used in AI applications such as autonomous vehicles, medical imaging, or security. Therefore, image annotation plays a crucial role in AI/ML development in many sectors.

What is image annotation?

Supervised ML models require data labeling to work effectively. Image annotation is a subset of data annotation where the labeling process focuses only on visual digital data such as images and videos. 

Image annotation often requires manual work. An engineer determines the labels or “tags” and passes the image-specific information to the computer vision model being trained. You can think of this process like the questions a child asks her parents to explore the environment in which she lives. The parents categorize the data into universal phrases such as bananas, oranges, cats, etc., as shown in the below image.

Why is image annotation important now?

Computer vision has already changed our lives with applications in healthcare, automotive, or marketing. According to Forbes, the computer vision market value will be around $50 billion in 2023 and PWC predicts that driverless cars could account for 40% of miles driven by 2030.

What are the techniques for image annotation?

There are five main techniques of image annotation, namely:

Bounding box





Bounding box

A frame is drawn around the object to be identified. Bounding boxes can be used for both two- and three-dimensional images.


Landmarking is an effective technique for identifying facial features, gestures, facial expressions and emotions. It is also used to mark body position and orientation. As shown in the figure below, data labelers mark specific locations on the face, such as eyes, eyebrows, lips, forehead, and so on with specific numbers by using this information ML model learns the parts of the human face.


These are pixel-level annotations that hide some areas of an image and make other areas of interest more visible. You can think of this technique as an image filter that makes it easier to focus on certain areas of the image.


This technique is used to mark the pick point of the target object and frame its edges: The polygon technique is a useful tool for labeling objects with irregular shapes.


The polyline technique helps create ML models for computer vision that guide autonomous vehicles. It ensures ML models recognize objects on the road, directions, turns, and oncoming traffic to perceive the environment for safe driving.

How to annotate images and videos?

Your company needs an image annotation tool to label the visual data. There are vendors that offer such tools for a fee. There are also open source image labeling tools that you can use freely. Moreover, they are modifiable, which means you can change them according to your business needs.

Developing your own tool for image annotation could be an alternative to outsourcing software. However, like all in-house activities, this is a more time-consuming and capital-intensive approach. However, if you have sufficient resources and feel that the templates available on the market do not meet your requirements, developing your own tool is possible.

To learn more, check out our comprehensive articles on video annotation and video annotation tools

In-housing vs outsourcing vs crowdsourcing?

Image annotation techniques require some manual work. Deciding who should perform this manual task is an important strategic decision for organizations. It is because the main methods, namely in-house, outsourcing and crowdsourcing, offer different levels of cost, output quality, data security, etc. 

OutsourceIn-houseCrowdsource Time requiredAverageHighLow PriceAverageExpensiveCheap Quality of labelingHighHighLow SecurityAverageHighLow

You can check our sortable/filterable list of data labeling/annotation/classification vendors list.

To learn more about annotation you can also read our text and audio annotation articles. If you also need help choosing vendors for image annotation, we can help:

Cem regularly speaks at international technology conferences. He graduated from Bogazici University as a computer engineer and holds an MBA from Columbia Business School.





Best Ai Image Generators 2023

Are you looking for the best AI image generators in 2023? Look no further! Artificial intelligence has come a long way in recent years and can now generate stunning, high-quality images that are indistinguishable from those created by humans. In this article, we will explore the top AI image generators available in 2023 and how they can help you create beautiful images for your business, website, or personal projects.

The world of digital marketing and content creation is constantly evolving, and businesses are always looking for new ways to stay ahead of the competition. In recent years, the use of AI image generators has become increasingly popular, and for good reason. AI image generators use machine learning algorithms to create stunning images that are tailored to your specific needs, and they can do it quickly and efficiently.

In this article, we will explore the best AI image generators available in 2023, and we will look at how they can help you create beautiful images for your business, website, or personal projects. Whether you are a professional photographer, a graphic designer, or a marketer, these tools can help you save time and create high-quality images that will help you stand out from the crowd.

Also read: 7 Best Free AI Art Generators to use in 2023

Using AI image generators can provide several benefits, including:

Saving Time: AI image generators can create high-quality images quickly and efficiently, which can save you a lot of time compared to traditional image creation methods.

Cost-Effective: AI image generators are often more cost-effective than hiring a professional photographer or graphic designer, making them a great option for small businesses and individuals.

Consistency: AI image generators can create images that are consistent in style and quality, which can help to create a strong brand image.

Customizability: AI image generators often allow you to customize your images to your specific needs, whether that be adding text, changing colors, or tweaking the overall style.

Versatility: AI image generators can create a wide range of images, from abstract art to realistic portraits, which makes them a versatile tool for a variety of different projects.

Ease of Use: AI image generators are often very easy to use and require little to no technical knowledge, which means anyone can use them to create high-quality images.

Also read: How To Generate AI Images From Text Free 2023

With so many different AI image generators available, it can be difficult to know which one to choose. Here are a few factors to consider when making your decision:

Ease of Use: If you are new to AI image generators, you may want to choose a tool that is easy to use and requires little to no technical knowledge.

Customizability: Consider whether the tool allows you to customize your images to your specific needs, whether that be adding text, changing colors, or tweaking the overall style.

Cost: Some AI image generators are free to use, while others require a subscription or a one-time fee. Consider your budget and choose a tool that fits within your financial constraints.

Versatility: Consider what types of images you want to create and choose a tool that is capable of creating those types of images.

DALL-E 2 is an AI image generator that uses CLIP to produce high-quality images based on text prompts. It offers both outpainting and inpainting features, allowing users to generate images with specific details or remove unwanted elements from existing images. Its unique approach to image generation makes it ideal for creative professionals and enthusiasts alike. DALL-E 2 can be used to create illustrations, design products, and generate new ideas for business. The tool has an easy-to-use interface that makes it possible for anyone, including amateur artists, to create high-quality images with AI. Users can customize multiple layers of the image using tools like the paintbrush, which allows them to add details like shadows and highlights.

Midjourney is an AI image generator that utilizes StyleGAN2 to create high-quality images. Its standout feature is its ability to generate incredibly accurate art images that are visually stunning. It can be accessed via Discord, and its user interface can be a bit complex for beginners. It offers a free beta program that provides a limited number of image generation credits, and once users exhaust the beta program’s limit, they have to buy a subscription.

Canva is a popular and user-friendly AI image generator that allows users to create professional-looking designs. It offers a variety of features, including the ability to create images from text prompts. Canva provides a library of templates and graphics that can be utilized to create images, making it easy for beginners to create unique and stunning visuals. It also allows for customization and editing of images, giving users control over the final product.

Check out: Canva AI Image Generator

PicSo is an AI image generator that uses Generative Adversarial Networks (GANs) to produce high-quality and unique images. Its main feature is that it offers the ability to create anime-style images, making it an attractive option for anime enthusiasts. Users can input text prompts or choose from the available options, and the platform will generate an image based on the input. It is available on Android and iPhone.

NightCafe is a well-known AI art generator with more algorithms and options than other generators, suitable for novice users, and has a generous free tier. It is based on a credit system, but credits can be earned by participating in the community or bought with a 15% discount using the code UNITEAI. NightCafe allows users to own their creations, organise them into collections, bulk-download all their images, create videos, and buy prints of their artwork.

Shutterstock is an established company that provides stock photography, stock footage, and stock music, and now offers the best tools to generate images and art using OpenAI’s DALL-E 2’s image-generating AI system. It combines this state-of-the-art AI generation system with a user-friendly platform that makes it fast and simple to use. Users can imagine anything and type it into the search bar, and Shutterstock will generate a few versions for them to choose from. They can then edit the image in Create, if they like, or license and download it. Users can license up to 10 AI-generated images for free with Shutterstock’s Free Trial Offer.

Deep Dream Generator by Aifnet is another popular AI art generator that relies on a neural network trained with millions of images to create realistic images. It allows users to choose a category such as animals or landscapes before creating a realistic image based on it. Users can also choose from three styles: Deep Style, Thin Style, or Deep Dream, and preview the image before downloading it. The tool is mainly used for creating artwork with different painting styles to generate images that appear to be from different places or periods of time.

In conclusion, AI image generators are a powerful tool that can help you create stunning images quickly, efficiently, and cost-effectively. Whether you are a professional photographer, a graphic designer, or a marketer, these tools can help you save time and create high-quality images that will help you stand out from the crowd. When choosing an AI image generator, consider factors such as ease of use, customizability, cost, and versatility to find the tool that best fits your needs.

So, if you’re looking for the best AI image generators in 2023, be sure to check out the tools we’ve listed above. And don’t forget to experiment with different styles and techniques to create truly unique and original images.

Share this:



Like this:




Image Optimizer Software: 10 Best To Use In 2023

Image Optimizer Software: 10 Best to Use in 2023




Having optimized images is crucial for websites that rely on conversions and


traffic as those can slow down the page.

Our top list will help you choose the right software that can easily optimize and



ess images

We’ve included both downloadable software, as well as websites that can compress images.

We’ve included general features, pros, and cons, all so you can make a more informed choice.

Image optimization is essential for both professional and home use. This is especially important if you’re an online publisher or blogger. Most of the websites (focus on social networks) have limitations for image size.

So, you have to optimize photos in order to use them online.

In addition, the large image files that you add from your gallery will increase website page size and thus, largely increase loading time. And we certainly don’t want that. Because the common visitor wants that page to load in a blink.

On the other hand, we neither want to trade so much of the image quality for improving the site speed. So, compromising between size and quality is the only viable option.

In that manner, we’ve prepared some fast, online and offline tools for image compression and optimization. All of them are free to use.

Optimizing images can mean a lot of things, from improving clarity to removing unwanted objects or retouching photographs, so a good all-around tool is what you need in this case.

InPixio’s Photo Studio is one such tool, and it offers you its entire toolset so that you can optimize any image in whatever way you feel like it.

It doesn’t matter if you want to tweak the color balance of a landscape, remove the wrinkles out of a selfie, or remove people from a family photo, InPixio Photo Studio Pro 12 does it all to great effect.

The best part about the program is that it isn’t hard to use either, with intuitively-placed brush tools, filters, and other useful tools that one may frequently use during image enhancement.

However, if you want to use it simply to compress or resize a photo with as little quality loss as possible, then InPixio is just what you need.

Create unique photomontages and switch vibrant skies from preset backgrounds in the library to awe your followers on Facebook and Twitter.

Photo Studio Pro 12

Optimize and perfect your photos with the help of this user-friendly image editing tool.

Check price Visit website

This is how you can revive some of your lifetime memories! Photoshop Elements is the first solution to check out if you plan to master incredible snapshots without being overwhelmed by the full potential of the original Photoshop app.

This amazing image optimization software provides featured rich tools such as innovative photo and video effects, automated editing options, and a large array of entertaining slideshows and collages with attractive templates.

Photoshop Elements doesn’t just convert black-and-white photos into color ones, but Automatic Colorization lets you play around with substituting or enhancing colors.

Thanks to the included Additional Guided Edits, you get step-by-step guidance from Adobe Sensei for creating borders, partial-image sketches, fun memes for social media, watercolors, and background replacements.

No less important, you and your loves ones should always look perfect. It’s nearly impossible to get everyone in a photo to have perfect skin and open eyes at the exact same instant.

Features such as Smooth Skin or Open Closed Eyes are intended to gently hide wrinkles and freckles or fix those presumably lost shots and re-open sleepers’ eyes.

The trick lies in automatically applying the eyes from the source image and replacing the closed eyes.

On top of that, Photoshop Elements is fully packed with powerful search and auto curation tools. These can be very useful if you don’t want to end up cluttering the main editing application.

Files remain in their original format and there is no need to unzip before using them. It also allows you to customize the balance between quality and compression ratio, which is a very useful feature for images.

You can also optimize files from within Windows Explorer and Microsoft Office programs, or choose to automatically optimize email attachments as they are sent.

This tool can be tried for free, but, if it fits your long-term needs and the features from the trial are not enough to accomplish your work – you can buy the full version.

⇒ Check it on the Official Website is a great online image/photo compressing tool. It lets you choose between two compressing modes: Lossless or Lossy.

Lossless will optimize the size of your photos while maintaining the image quality at the same. Lossy will compress the photo more but will reduce its quality.

The lossless mode supports only JPEG and PNG formats, while Lossy works out with the following 4 formats:





The Compressor is simple to use. You select a preferred optimizing mode, upload your image and it gets automatically optimized. A nice addition is a split-screen preview that lets you see the exact difference in transition.

A tool supports only one file per compression up to 10 MBs of size.

You can find chúng tôi here.

⇒ Try

Furthermore, the files can be compressed from 1 up to 99 percent, but have in mind that photos will lose a lot of original quality.

The procedure is simple:

⇒ Try JPEG Optimizer

Optimizilla is a well-designed online tool for image optimizing. The interface is great and easy to use.

Expert tip:

Even though some other solutions support more formats, most of them don’t have the drag-and-drop option. To optimize your photo using this tool, do as follows:

Choose up to 20 files, drag-and-drop them in a marked area.

Once uploaded, select an individual file in the queue.

Use sliders to choose optimization level (more quality – less compression).

Compare images to find wanted optimization.

Download files in the standard manner or in a ZIP archive.

⇒ Try Optimizilla utilizes similar features as most of the other optimization tools. But it goes one step further. It has a premium version called KrakenPro. In addition, it supports cloud store input.

Same as Optimizilla, you can drag and drop files in the marked area. However, a free version is limited to 1 MB per file so this may be a deal-breaker for some users. In addition, there is no image preview on the site.

Select an optimization model.

Drag photos from desktop or import from Box/Google Drive/Dropbox.

Download files individually or in a ZIP archive.

⇒ Try

Resize Photos trades interface simplicity for an abundance of options. Yes, you can just select simple optimization and resize the selected image. But there is much more you can do. For start, you can modify output format.

Once the photo is uploaded, there is a variation of different features. Some of them are shadows, effects, and captions. It supports only one file per conversion which can be JPEG, PNG, GIF, BMP, or PSD format, respectively.

To optimize your photo/image with Resize Photos, follow the instructions:

Upload photo with a supported format.

Select width in pixels.

Choose post-optimization photo quality.

Select wanted output format.

If needed, modify additional settings.

Apply to inspect changes.

Once finished editing, download image.

⇒ Try Resize Photos

Convert Image is a simple, but quite useful online compression tool.  Its distinctive feature is multiple input-output file choices, with most of them unavailable with other online solutions.

You can compress only one photo per conversion up to 24 MB. A tool offers tips about compression levels and preview images.

That way you’ll get full insight into the image export quality. Though, switching between the output format is somehow complicated and confusing.

To compress photos/images with Convert Image, do as follows:

The default output format is JPEG. To choose other extensions, scroll to the bottom of the page.

Upload photo and Agree to the Terms of Use.

Download compressed photo.

⇒ Try Convert Image

TinyPNG is one of the simplest online optimization solutions that offer great compression without quality loss.

It merely decreases the number of colors in the image without reducing its quality. However, you can’t tweak anything compared to some other available solutions.

It supports only 2 main formats: JPEG and PNG. Per conversion, you can compress up to 20 files with 5 MB as a single file limit. After the conversion, the file-bundle is downloaded as a ZIP archive.

Additionally, it offers premium service and WordPress and Photoshop plugins for a modest price. Finished photos can be directly downloaded or transferred to a Dropbox.

To optimize photos/images with TinyPNG, do as follows:

Drag and drop preferred files in the marked area(up to 20).

Wait until the automatic optimization is done.

Download compressed files or export them to Dropbox.

To compress your photos using TinyPNG, go here.

⇒ Try TinyPNG

We now move onto the free third-party applications. You’ll need to download and install those, but they’ll reward you with improved features and basic editing possibilities.

The first tool we are presenting you with is RIOT (Radical Image Optimization Tool). RIOT is, as its name speaks for itself, an image optimization tool with various features.

The interface is intuitive and user-friendly, so even newbies will find it easy to use. The most noteworthy difference comparing to online tools are formats.

RIOT supports all basic image/photo formats with the addition of PSD, RAW, HDR, and even a few unusual scientific formats.

Besides compression, you can use RIOT as a full optimization tool for all the operations needed (cropping, rotating, adjusting brightness, or gamma). On the other hand, we are here for the automatic optimization feature.

It works fast and your photos will be as good as they were before the size reduction. The automatic preview will let you see all the changes, with both dual or single view.

Additionally, multiple compressions can be done parallelly, and you can choose the output size threshold. RIOT also comes as a plugin for GIMP, IrfanView, or XnView.

If you are keen to move from browser to desktop, you can find RIOT, here.

⇒ Try RIOT

No matter what option you choose, optimizing your photos for online implementation is imperative. On the other hand, images you upload must maintain a certain quality and be a valid addition to your site.

So, trying to balance between those two is the key.

Was this page helpful?


Implementing Artificial Neural Network(Classification) In Python From Scratch

This article was published as a part of the Data Science Blogathon

Neural networks. One of the booming technological breakthroughs in the 21st century.

Are you interested in creating your own neural network from scratch in Python?. Well, you are at the right place. In this article, we will be creating an artificial neural network from scratch in python. The Artificial Neural Network that we are going to develop here is the one that will solve a classification problem. So stretch your fingers, and let’s get started.

Interesting Sidenote

Artificial Neural Networks(ANN) are part of supervised machine learning where we will be having input as well as corresponding output present in our dataset. Our whole aim is to figure out a way of mapping this input to the respective output. ANN can be used for solving both regression and classification problems.

From the perspective of this blog, we will be developing an ANN for solving the classification class of problems.

Pre-Requisites for Artificial Neural Network Implementation

Following will be the libraries and software that we will be needing in order to implement ANN.

1. Python – 3.6 or later

2. Jupyter Notebook ( Google Colab can also be used )

3. Pandas

4. Numpy

5. Tensorflow 2. x

6. Scikit-Learn

Understanding the Problem Statement for Artificial Neural Network

Here we are dealing with a dataset from the finance domain. We have a dataset where we are having 14 dimensions in total and 100000 records. The dimensions that we will be dealing with are as follows:-

RowNumber:- Represents the number of rows

CustomerId:- Represents customerId

Surname:- Represents surname of the customer

CreditScore:- Represents credit score of the customer

Geography:- Represents the city to which customers belongs to

Gender:- Represents Gender of the customer

Age:- Represents age of the customer

Tenure:- Represents tenure of the customer with a bank

Balance:- Represents balance hold by the customer

NumOfProducts:- Represents the number of bank services used by the customer

HasCrCard:- Represents if a customer has a credit card or not

IsActiveMember:- Represents if a customer is an active member or not

EstimatedSalary:- Represents estimated salary of the customer

Exited:- Represents if a customer is going to exit the bank or not.

Structure of dataset

As we can see from the above data dictionary, we are dealing with a total of 14 dimensions.

Here our main goal is to create an artificial neural network that will take into consideration all independent variables(first 13) and based on that will predict if our customer is going to exit the bank or not(Exited is dependent variable here).

Once we understand the steps for constructing neural networks, we can directly implement those same steps to other datasets as well.

One of the ways where we can find such datasets is the UCI machine learning repository. These datasets are classified into regression and classification problems. Since we are implementing this neural network to solve classification problems, you can download any classification dataset from there and can apply the same steps on any dataset of your choice !. How cool is that?

Importing Necessary Libraries for Artificial Neural Network

Let’s import all the necessary libraries here

#Importing necessary Libraries import numpy as np import pandas as pd import tensorflow as tf Importing Dataset

In this step, we are going to import our dataset. Since our dataset is in csv format, we are going to use the read_csv() method of pandas in order to load the dataset.

#Loading Dataset data = pd.read_csv("Churn_Modelling.csv") Generating Matrix of Features (X)

The basic principle while creating a machine learning model is to generate X also called as Matrix of Features. This X basically contains all our independent variables. Let’s create the same here.

Python Code:

Here I have used iloc method of Pandas data frame which allows us to fetch the desired values from the desired column within the dataset. Here as we can see that we are fetching all the data from the 3rd column till the last minus one column. The reason for that is the first 3 columns i.e RowNumber, CustomerId, and Surname have nothing to do with deciding whether the customer is going to exit or not. Hence in this case we started fetching all the values from the 3rd column onwards. Lastly, since our last column is basically a dependent variable hence we have mentioned -1 in iloc method using which allows us to exclude the last column from being included in our matrix of features X.

Generating Dependent Variable Vector(Y)

In the same fashion where we have created our matrix of features(X) for the independent variable, we also have to create a dependent variable vector(Y) which will only contain our dependent variable values.

#Generating Dependent Variable Vectors Y = data.iloc[:,-1].values Encoding Categorical Variable Gender

Now we have defined our X and Y, from this point on we are going to start with one of the highly time-consuming phases in any machine learning problem-solving. This phase is known as feature engineering. To define it in a simple manner, feature engineering is a phase where we either generate new variables from existing ones or modify existing variables so as to use them in our machine learning model.

In the above image depicting the structure of the dataset, we can see that most of the variables are numeric in nature with exception of a few – Gender, Country. Essentially, a machine learning model is a mathematical formula that is only going to accept digits as input. So we try to create an ML model using this dataset which contains a mix of data( numeric + string), our model will simply fail during the creation process itself. Hence we need to convert those string values into their numerical equivalent without losing their significance.

One of the most efficient ways of doing this is by using a technique called encoding. It is a process that will convert strings or categories directly into their numerical equivalent without losing significance.

Here our gender column has only 2 categories which are male and female, we are going to use LabelEncoding. This type of encoding will simply convert this column into a column having values of 0 and 1. In order to use Label Encoding, we are going to use LabelEncoder class from sklearn library.

#Encoding Categorical Variable Gender from sklearn.preprocessing import LabelEncoder LE1 = LabelEncoder() X[:,2] = np.array(LE1.fit_transform(X[:,2]))

Here we have applied label encoding on the Gender column of our dataset.

Encoding Categorical Variable Country

Now let’s deal with another categorical column named country. This column has a cardinality of 3 meaning that it has 3 distinct categories present i.e France, Germany, Spain.

Here we have 2 options:-

1. We can use Label Encoding here and directly convert those values into 0,1,2 like that

2. We can use One Hot Encoding here which will convert those strings into a binary vector stream. For example – Spain will be encoded as 001, France will be 010, etc.

The first approach is easy and faster to implement. However, once those values are encoded, those will be converted into 0,1,2. However, there does exist another method of encoding known as one-hot encoding. In one hot encoding, all the string values are converted into binary streams of 0’s and 1’s. One-hot encoding ensures that the machine learning algorithm does not assume that higher numbers are more important.

#Encoding Categorical variable Geography from sklearn.preprocessing import OneHotEncoder ct =ColumnTransformer(transformers=[('encoder',OneHotEncoder(),[1])],remainder="passthrough") X = np.array(ct.fit_transform(X))

Here we have used OneHotEncoder class from sklearn in order to perform one-hot encoding. Now you might have a query here. What is the use of ColumnTransformer? Well, ColumnTransformer is another class in sklearn that will allow us to select a particular column from our dataset on which we can apply one-hot encoding.

Splitting Dataset into Training and Testing Dataset

In this step, we are going to split our dataset into training and testing datasets. This is one of the bedrocks of the entire machine learning process. The training dataset is the one on which our model is going to train while the testing dataset is the one on which we are going to test the performance of our model.

#Splitting dataset into training and testing dataset from sklearn.model_selection import train_test_split X_train,X_test,Y_train,Y_test = train_test_split(X,Y,test_size=0.2,random_state=0)

Here we have used the train_test_split function from the sklearn library. We have split our dataset in a configuration such that 80 percent of data will be there in the training phase and 20 percent of data will be in the testing phase.

Additionally, the best part about using the train_test_split function from sklearn is that, while splitting it will also be performing data shuffling in order to create a more generalized dataset.

Performing Feature Scaling

The very last step in our feature engineering phase is feature scaling. It is a procedure where all the variables are converted into the same scale. Why you might ask?. Sometimes in our dataset, certain variables have very high values while certain variables have very low values. So there is a chance that during model creation, the variables having extremely high-value dominate variables having extremely low value. Because of this, there is a possibility that those variables with the low value might be neglected by our model, and hence feature scaling is necessary.

Now here I am going to answer one of the most important questions asked in a machine learning interview. ” When to perform feature scaling – before the train-test split or after the train-test split?”.

Well, the answer is after we split the dataset into training and testing datasets. The reason being, the training dataset is something on which our model is going to train or learned itself. While the testing dataset is something on which our model is going to be evaluated. If we perform feature scaling before the train-test split then it will cause information leakage on testing datasets which neglects the purpose of having a testing dataset and hence we should always perform feature scaling after the train-test split.

Now how we are going to perform feature scaling? Well, there are many ways of performing feature scaling. The two most efficient techniques in the context are:-

1. Standardization

2. Normalization

Whenever standardization is performed, all values in the dataset will be converted into values ranging between -3 to +3. While in the case of normalization, all values will be converted into a range between -1 to +1.

There are few conditions on which technique to use and when. Usually, Normalization is used only when our dataset follows a normal distribution while standardization is a universal technique that can be used for any dataset irrespective of the distribution. Here we are going to use Standardization.

#Performing Feature Scaling from sklearn.preprocessing import StandardScaler sc = StandardScaler() X_train = sc.fit_transform(X_train) X_test = sc.transform(X_test)

Here we have used StandardScalar class from the sklearn library in order to perform standardization.

Now we have completed our feature engineering phase. We can now start with the creation of our artificial neural network from the next point onwards.

Initializing Artificial Neural Network

This is the very first step while creating ANN. Here we are going to create our ann object by using a certain class of Keras named Sequential.

#Initialising ANN ann = tf.keras.models.Sequential()

As a part of tensorflow 2.0, Keras is now integrated with tensorflow and is now considered as a sub-library of tensorflow. The Sequential class is a part of the models module of Keras library which is a part of the tensorflow library now.

Creating Hidden Layers

Once we initialize our ann, we are now going to create layers for the same. Here we are going to create a network that will have 2 hidden layers, 1 input layer, and 1 output layer. So, let’s create our very first hidden layer

 #Adding First Hidden Layer ann.add(tf.keras.layers.Dense(units=6,activation="relu"))

Here we have created our first hidden layer by using the Dense class which is part of the layers module. This class accepts 2 inputs:-

1. units:- number of neurons that will be present in the respective layer

2. activation:- specify which activation function to be used

For the first input, I had tested with many values in the past and the optimal value that I had found is 6. Obviously, we can try with any other value as there is no hard rule about the number of neurons that should be present in the layer.

For the second input, we are always going to use “relu”[rectified linear unit] as an activation function for hidden layers. Since we are going to create two hidden layers, this same step we are going to repeat for the creation of the second hidden layer as well.

 #Adding Second Hidden Layer ann.add(tf.keras.layers.Dense(units=6,activation="relu")) Creating Output Layer

In this step, we are going to create our output layer for ann. The output layer will be responsible for giving output.

 #Adding Output Layer ann.add(tf.keras.layers.Dense(units=1,activation="sigmoid"))

Here again, we are going to use the Dense class in order to create the output layer. Two important things to remember here:-

1. In a binary classification problem(like this one) where we will be having only two classes as output (1 and 0), we will be allocating only one neuron to output this result. For the multiclass classification problem, we have to use more than one neuron in the output layer. For example – if our output contains 4 categories then we need to create 4 different neurons[one for each category].

2. For the binary classification Problems, the activation function that should always be used is sigmoid. For a multiclass classification problem, the activation function that should be used is softmax.

Here since we are dealing with binary classification hence we are allocating only one neuron in the output layer and the activation function which is used is softmax.

Compiling Artificial Neural Network

We have now created layers for our neural network. In this step, we are going to compile our ANN.

#Compiling ANN

We have used compile method of our ann object in order to compile our network. Compile method accepts the below inputs:-

1. optimizer:- specifies which optimizer to be used in order to perform stochastic gradient descent. I had experimented with various optimizers like RMSProp, adam and I have found that adam optimizer is a reliable one that can be used with any neural network.

2. loss:- specifies which loss function should be used. For binary classification, the value should be binary_crossentropy. For multiclass classification, it should be categorical_crossentropy.

3. metrics:- which performance metrics to be used in order to compute performance. Here we have used accuracy as a performance metric.

Fitting Artificial Neural Network

This is the last step in our ann creation process. Here we are just going to train our ann on the training dataset.

#Fitting ANN,Y_train,batch_size=32,epochs = 100)

Here we have used the fit method in order to train our ann. The fit method is accepting 4 inputs in this case:-

1.X_train:- Matrix of features for the training dataset

2.Y_train:- Dependent variable vectors for the training dataset

3.batch_size: how many observations should be there in the batch. Usually, the value for this parameter is 32 but we can experiment with any other value as well.

4. epochs: How many times neural networks will be trained. Here the optimal value that I have found from my experience is 100.

Are you interested to see how the training process looks like? Well here is the snap for the same.

Training of Artificial Neural Network

Here we can see that in each epoch our loss is decreasing and our accuracy is increasing. As we can see here that our final accuracy is 86.59 which is pretty remarkable for a neural network with this simplicity.

That’s it :). We have created our artificial neural network from scratch using Python.

As an additional bonus, I am attaching the code below that will allow us to perform single-point prediction for any custom values of input.

Predicting Result for Single Point Observation #Predicting result for Single Observation



Here our neural network is trying to predict whether our customer is going to exit or not based on the values of independent variables


Now we have created our model. I am giving you a pro tip now on how can you save your created neural network.

#Saving created neural network"ANN.h5")

That’s it. Using this one line of code allows us to save our ML model. You might have a query here?

What is the h5 file format? Well, h5 is a specific file format used by neural networks. Using this format we can directly save our neural network as a serialized object. It is similar to the pickle file format implementation that we use for storing traditional machine learning models.

Well, that’s all about implementing neural networks from scratch in Python.

If you’re an enthusiast who is looking forward to unravel the world of Generative AI. Then, please register for our upcoming event, DataHack Summit 2023.


Hope you like this article.

The media shown in this article are not owned by Analytics Vidhya and are used at the Author’s discretion.


Fake News Classification Using Deep Learning

This article was published as a part of the Data Science Blogathon.


Here’s a quick puzzle for you. I’ll give you two titles, and you’ll have to tell me which is fake. Ready? Let’s get started:

“Wipro is planning to buy an EV-based startup.”

Well, it turns out that both of those headlines were fake news. In this article, you will learn the fake news classification using deep learning.

Image – 1

The grim reality is that there is a lot of misinformation and disinformation on the internet. Ninety per cent of Canadians have fallen for false news, according to a 2023 research done by Ipsos Public Affairs for Canada’s Centre for International Governance Innovation.

It got me thinking: is it feasible to build an algorithm that can tell whether an article’s title is fake news? Well, it appears to be the case!

In this post, we go through the exploration of the classification model with BERT and LSTMs to identify the fake new classification.

Go through this Github link to view the complete code.

Dataset for Fake News Classification

We use the dataset from Kaggle. It consists of 2095 article details that include author, title, and other information. Go through the link to get the dataset.


Let us start analyzing our data to get better insights from it. The dataset looks clean, and now we map the values to our class Real and Fake such as 0 and 1.

data = pd.read_csv('/content/news_articles.csv') data = data[['title', 'label']] data['label'] = data['label'].map({'Real': 0, 'Fake':1}) data.head()

Image by Author

Since we have 1294 samples of real news and 801 samples of fake news, there is an approximately 62:38 news ratio. It means that our dataset is relatively biased. For our project, we consider the title and class columns.

Now, we can analyze the trends present in our dataset. To get an idea of dataset size, we get the mean, min, and max character lengths of titles. We use a histogram to visualize the data.

# Character Length of Titles - Min, Mean, Max print('Mean Length', data['title'].apply(len).mean()) print('Min Length', data['title'].apply(len).min()) print('Max Length', data['title'].apply(len).max()) x = data['title'].apply(len).plot.hist()

Image by Author

We can observe that characters in each title range from 2-443. We can also see that more per cent of samples with a length of 0-100. The mean length of the dataset is around 61.

Preprocessing Data

Now we will use the NLTK library to preprocess our dataset, which includes:


It is the process of dividing a text into smaller units (each word will be an index in an array)


It removes the endings of the word to the root word. It reduces the word children to a child.

Stop words Removal:

Words like the and for will be eliminated from our dataset because they take too much room.

#Import nltk preprocessing library to convert text into a readable format import nltk from nltk.tokenize import sent_tokenize from chúng tôi import WordNetLemmatizer from nltk.corpus import stopwords'punkt')'wordnet')'stopwords') data['title'] = data.apply(lambda row: nltk.word_tokenize(row['title']), axis=1) #Define text lemmatization model (eg: walks will be changed to walk) lemmatizer = WordNetLemmatizer() #Loop through title dataframe and lemmatize each word def lemma(data): return [lemmatizer.lemmatize(w) for w in data] #Apply to dataframe data['title'] = data['title'].apply(lemma) #Define all stopwords in the English language (it, was, for, etc.) stop = stopwords.words('english') #Remove them from our dataframe data['title'] = data['title'].apply(lambda x: [i for i in x if i not in stop]) data.head()

Image by Author

We create two models using this data for text classification:

An LSTM model (Tensorflow’s wiki-words-250 embeddings)

A BERT model.

LSTM Model for Fake News Classification

We split our data into a 70:30 ratio of train and test.

#Split data into training and testing dataset title_train, title_test, y_train, y_test = train_test_split(titles, labels, test_size=0.3, random_state=1000)

To get predictions based on the text from our model, we need to encode it in vector format then it is processed by the machine.

Word2Vec Skip-Gram architecture had used by TensorFlow’s wiki-words-250. Based on the input, Skip-gram had trained by predicting the context.

Consider this sentence as an example:

I am going on a voyage in my car.

The word voyage passed as input and one as the window size. The window size means before and after the target word to predict. In our case, the words are gone and car (excluding stopwords, and go is the lemmatized form of going).

We one-hot-encode our word, resulting in an input vector of size 1 x V, where V is the vocabulary size. A weight matrix of V rows (one for each word in our vocabulary) and E columns, where E is a hyperparameter indicating the size of each embedding, will be multiplied by the representation. Except for one, all values in the input vector are zero because it is one-hot encoded (representing the word we are inputting). Finally, when the weight matrix had multiplied by the output, a 1xE vector denotes the embedding for that word.

The output layer, which consists of a softmax regression classifier, will receive the 1xE vector. It had built of V neurons (which correspond to the vocabulary’s one-hot encoding) that produce a value between 0 and 1 for each word, indicating the likelihood of that word being in the window size.

Word embeddings with a size E of 250 are present in Tensorflow’s wiki-words-250. Embeddings applied to the model by looping through all of the words and computing the embedding for each one. We’ll need to utilize the pad sequences function to adjust for samples of variable lengths.

#Convert each series of words to a word2vec embedding indiv = [] for i in title_train: temp = np.array(embed(i)) indiv.append(temp) #Accounts for different length of words indiv = tf.keras.preprocessing.sequence.pad_sequences(indiv,dtype=’float’) indiv.shape

Therefore, there are 1466 samples in the training data, the highest length is 46 words, and each word has 250 features.

Now, we build our model. It consists of:

1 LSTM layer with 50 units

2 Dense layers (first 20 neurons, the second 5) with an activation function ReLU.

1 Dense output layer with activation function sigmoid.

We will use the Adam optimizer, a binary cross-entropy loss, and a performance metric of accuracy. The model will be trained over 10 epochs. Feel free to further adjust these hyperparameters.

#Sequential model has a 50 cell LSTM layer before Dense layers model = tf.keras.models.Sequential() model.add(tf.keras.layers.LSTM(50)) model.add(tf.keras.layers.Dense(20,activation='relu')) model.add(tf.keras.layers.Dense(5,activation='relu')) model.add(tf.keras.layers.Dense(1,activation='sigmoid')) #Compile model with binary_crossentropy loss, Adam optimizer, and accuracy metrics loss="binary_crossentropy", metrics=['accuracy']) #Train model on 10 epochs, y_train,validation_data=[test,y_test], epochs=20)

We get an accuracy of 59.4% on test data.

Using BERT for Fake News Classification

What would you reply if I asked you to name the English term with the most definitions?

That word is “set,” according to the Oxford English Dictionary’s Second Edition.

If you think about it, we could make a lot of different statements using that term in various settings. Consider the following scenario:

I set the table for lunch

The problem with Word2Vec is that no matter how the word had used, it generates the same embedding. We use BERT, which can build contextualized embeddings, to combat this.

BERT is known as “Bidirectional Encoder Representations from Transformers.” It employs a transformer model to generate contextualized embeddings by utilizing attention mechanisms.

An encoder-decoder design had used in a transformer model. The encoder layer creates a continuous representation based on the data it has learned from the input. The preceding input is delivered into the model by the decoder layer, which generates an output. Because BERT’s purpose is to build a vector representation from the text, it only employs an encoder.

Pre-Training & Fine-Tuning

BERT had trained using two ways. The first method is known to be veiled language modelling. Before transmitting sequences, a [MASK] token had used to replace 15% of the words. Using the context supplied by the unmasked words, the model will predict the masked words.

It is accomplished by

Using embedding matrix to apply a classification layer to the encoder output. As a result, it will be the same size as the vocabulary.

Using the softmax function to calculate the likelihood of the word.

The second strategy is to guess the upcoming sentence. The model will be given two sentences as input and predict whether the second sentence will come after the first. While training, half of the inputs are pairs, while the other half consists of random sentences from the corpus. To distinguish between the two statements,

Here, it adds a [CLS] token at the start of the first sentence and a [SEP] token at the end of each.

Each token (word) contains a positional embedding that allows information extracted from the text’s location. Because there is no repetition in a transformer model, there is no inherent comprehension of the word’s place.

Each token is given a sentence embedding (further differentiating between the sentences).

For Next Sentence Prediction, the output of the [CLS] embedding, which stands for “aggregate sequence representation for sentence classification,” is passed through a classification layer with softmax to return the probability of the two sentences being sequential.

Image by Author

Implementation of BERT

The BERT preprocessor and encoder from Tensorflow-hub had used. Do not run the content via the earlier-mentioned framework (which removes capitalization, applies lemmatization, etc.) The BERT preprocessor had used to abstract this.

We split our data for training and testing in the ratio of 80:20.

from sklearn.model_selection import train_test_split #Split data into training and testing dataset title_train, title_test, y_train, y_test = train_test_split(titles, labels, test_size=0.2, random_state=1000)

Now, load Bert preprocessor and encoder

# Use the bert preprocesser and bert encoder from tensorflow_hub

We can now work on our neural network. It must be a functional model, with each layer’s output serving as an argument to the next.

1 Input layer: Used to pass sentences into the model.

The bert_preprocess layer: Preprocess the input text.

The bert_encoder layer: Pass the preprocessed tokens into the BERT encoder.

1 Dropout layer with 0.2. The BERT encoder pooled_output is passed into it.

2 Dense layers with 10 and 1 neurons. The first uses a ReLU activation function, and the second is sigmoid.

import tensorflow as tf # Input Layers input_layer = tf.keras.layers.Input(shape=(), dtype=tf.string, name='news') # BERT layers processed = bert_preprocess(input_layer) output = bert_encoder(processed) # Fully Connected Layers layer = tf.keras.layers.Dropout(0.2, name='dropout')(output['pooled_output']) layer = tf.keras.layers.Dense(10,activation='relu', name='hidden')(layer) layer = tf.keras.layers.Dense(1,activation='sigmoid', name='output')(layer) model = tf.keras.Model(inputs=[input_layer],outputs=[layer])

The “pooled output” will be transmitted into the dropout layer, as you can see. This value represents the text’s overall sequence representation. It is, as previously said, the representation of the [CLS] token outputs.

The Adam optimizer, a binary cross-entropy loss, and an accuracy performance metric had used. For five epochs, the model had trained. Feel free to tweak these hyperparameters even more.

#Compile model on adam optimizer, binary_crossentropy loss, and accuracy metrics #Train model on 5 epochs, y_train, epochs= 5) #Evaluate model on test data model.evaluate(title_test,y_test)

Image by Author

Above, you can see that our model achieved an accuracy of 61.33%.


To improve the model performance:

Train the models on a large dataset.

Tweak hyperparameters of the model.

I hope you had found this post insightful and a better understanding of NLP techniques for fake news classification.


Image – 1: Photo by Roman Kraft on Unsplash

The media shown in this article is not owned by Analytics Vidhya and are used at the Author’s discretion. 


Update the detailed information about Clarifying Image Recognition Vs. Classification In 2023 on the website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!