Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Hands-On Artificial Intelligence with Java for Beginners
Hands-On Artificial Intelligence with Java for Beginners

Hands-On Artificial Intelligence with Java for Beginners: Build intelligent apps using machine learning and deep learning with Deeplearning4j

eBook
€8.99 €15.99
Paperback
€19.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Artificial Intelligence with Java for Beginners

Introduction to Artificial Intelligence and Java

In this chapter, we'll be talking about what machine learning is, why we do machine learning, what supervised learning is, and what unsupervised learning is. We will also understand the difference between classification and regression. Following this, we will start with the installation of JDK and JRE, and will also set up NetBeans on our system. Toward the end of the chapter, we will download and use a JAR file for our project.

Therefore, we will be covering the following topics in this chapter:

  • What is machine learning?
  • Difference between classification and regression
  • Installing JDK and JRE
  • Setting up the NetBeans IDE
  • Importing Java libraries and exporting code in projects as a JAR file

Let's get started and see what the AI problems that are related to supervised and unsupervised learning are.

What is machine learning?

The capability of machine learning is actually the capability of adding new knowledge, or refining previous knowledge, that will help us in making the best or optimum decisions. Note the following, according to the economist and political scientist, Herbert Simon: 

"Learning is any process by which a system improves performance from experience."

There is a standard definition that has been given by Tom Mitchell, who is a computer scientist and E. Fredkin University Professor at the Carnegie Mellon University (CMU), that is as follows: 

"A program is said to learn from experience E with respect to some class of task T and performance measure P. If its performance at tasks in T, as measured by P, improves with experience E, then it is machine learning."

What this means is that when we have certain data and experiences available to us along with the help of a human expert, we are able to classify that particular data. For example, let's say we have some emails. With the help of a human, we can filter the emails as spam, business, marketing, and so on. This means that we are classifying our emails based on our experiences and classes of task T are the classes/filters that we have assigned to the emails.

With this data in mind, if we train our model, we can make a model that will classify emails according to our preferences. This is machine learning. We can always check whether the system has learned perfectly or not, which would be considered as a performance measure.

In this way, we will receive more data in the form of emails and we will be able to classify them, and it would be an improvement of the data. With that gained experience from the new data, the system's performance would improve.

This is the basic idea of machine learning.

The question is, why are we actually doing this?

We do this because we want to develop systems that are too difficult or expensive to construct manually – whether that's because they require specific detailed skills or knowledge tuned to a specific task. This is known as a knowledge engineering bottleneck. As humans, we don't have enough time to actually develop rules for each and every thing, so we look at data and we learn from data in order to make our systems predict things based on learning from data.

The following diagram illustrates the basic architecture of a learning system:

In the preceding diagram, we have a Teacher, we have Data, and we add Labels onto them, and we also have a Teacher who has assigned these labels. We give it to a Learner Component, which keeps it in a Knowledge Base, from which we can evaluate its performance and send it to a Performance Component. Here, we can have different evaluation measures, which we'll look at in future chapter, using which we can send Feedback to the Learner Component. This process can be improved and built upon over time.

The following diagram illustrates a basic architecture of how our supervised learning system looks:

Suppose we have some Training Data. Based on that, we can do some Preprocessing and extract features that are important. These Features will be given to a Learning Algorithm with some Labels attached that have been assigned by a human expert. This algorithm will then learn and create a Model. Once the Model has been created, we can take the new data, preprocess it, and extract features from it; based on those Features, we then send the data to a Model, which will do some kind of a Classification before providing a Decision. When we complete this process, and when we have a human who provides us with Labels, this kind of learning is known as supervised learning.

On the other hand, there is unsupervised learning, which is illustrated in the following diagram:

In unsupervised learning, we extract data and later Features before giving it to a Learning Algorithm, but there is no kind of human intervention that provides classification. In this case, the machine would group the data into smaller clusters, which is how the Model will learn. The next time features are extracted and given to a Model, the Model will provide us with four emails that belong to cluster 1, five emails that belong to cluster 3, and so on. This is known as unsupervised learning, and the algorithms that we use are known as clustering algorithms.

Differences between classification and regression

In our classification system, we have data that is used to train our model. In this case of sorting emails into clusters, discrete values are provided with the data, and this is known as classification.

There is another aspect of supervised learning, where instead of providing a discrete value, we provide it with a continuous value. This is known as regression. Regression is also considered supervised learning. The difference between classification and regression is that the first has discrete values and the latter has continuous, numeric values. The following diagram illustrates the three learning algorithms that we can use:

As you can see in the preceding diagram, we use Supervised Learning, Unsupervised Learning, and Reinforcement Learning. When we talk about Supervised Learning, we also use Classification. Within Classification, we perform tasks such as Identify Fraud Detection, Image Classification, Customer Retention, and Diagnostics. In Regression, we perform activities such as Advertising Popularity Prediction, Weather Forecasting, and so on. In Reinforcement, we perform Game AI, Skill Acquisition, and so on. Finally, in Unsupervised Learning, we have Recommender Systems and different sub-fields of machine learning, as illustrated.

Installing JDK and JRE

Since we will be coding in Java, we will need the Java Development Kit (JDK). JDK is an environment that comprises a compiler and an interpreter. The compiler is used to convert source code that is written in a high-level language into an intermediate form, which is byte code. That means that the JDK compiles the entire code and converts it into byte code. Once you have byte code, you need a Java interpreter, which is known as a Java Runtime Environment (JRE). JRE provides you with just the Java interpreter. If you have a JRE and byte code, you can run it on your system, as shown in the following diagram:

We will now download JDK onto our system.

Open your browser and go to the link https://www.oracle.com/technetwork/java/javase/downloads/index.html. Here, you will get an option to download Java. Currently, JDK 8 is supported by NetBeans. We have JDK 10, but it's not supporting NetBeans. If you don't have NetBeans in JDK, go to http://www.oracle.com/technetwork/java/javase/downloads/jdk-netbeans-jsp-142931.html. You have to accept the agreement, and based on your system, you can then download NetBeans and JDK, as shown in the following screenshot:

If you only want to install JDK, you have to go to JDK 8 at http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html. It will take you to the next page where you will also find more information about JDK 8, as follows:

Now, you have to accept the agreement again and download JDK according to your system requirements.

Once you have downloaded JDK, it is easy to install. For Windows and macOS, you just have to right-click on it. For Linux machines, you can either use a sudo or apt-get command on Ubuntu.

Setting up the NetBeans IDE

We will now download NetBeans onto our system. Visit the link at https://netbeans.org/downloads/. You should see something like the following screenshot:

Here, you will find information about the current NetBeans version, which is NetBeans 8.2. You can download either Java SE, Java EE, or any other NetBeans IDE Download Bundle. It is advisable that you download the All bundle because it supports all of the technologies, as seen in the preceding screenshot. You never know when you might need them! 

As shown on the top-right corner, 8.2 is the current version that you will be downloading. If you don't want to download this version, you can download its immediate predecessor, which is 8.1. If you want to download the experimental versions, which are the alpha or beta versions, click on Development. If you want to download versions that are earlier than 8.1, you can go to Archive, and this will help you in downloading the required version, as seen in the following screenshot: 

As shown in the preceding diagram, 8.2 is the latest version of NetBeans. There have been changes in subsequent versions of NetBeans, but we will be using 8.2. You can download older versions if you want. Versions such as 7.1 and 7.0.1, for example, work in a different way but can be used with older Java code.

Once you have downloaded NetBeans, you will get an .exe file on Windows. You just have to double-click on it and follow the instructions to install it. On a Mac, it will appear as a .dmg file; just click on it to install it. The installation process is simple, as you simply have to follow the prompts. On Linux, you will get a .sh file. Here, simply run the shell script and click on Next to proceed. NetBeans should now be installed on your machine!

Before installing NetBeans, make sure you have JDK installed. If not, you will get an error and NetBeans will not install on your system.

Importing Java libraries and exporting code in projects as a JAR file

We will now download a JAR file from the internet and use it in our project to create a JAR file for our project.

Open a web browser and search for download a junit.jar. This will take you to a link where you can download a JAR file. There are online repositories available where JAR files exist. One of the most reliable repositories can be found at http://www.java2s.com/Code/Jar/j/Downloadjunitjar.htm, where you can download any available JAR file. If you click on it, it should take you to the following page:

As seen in the preceding screenshot, you will find the junit.jar file and the different classes that are available in the JAR file also listed. You can right-click on the save (floppy disc) symbol to save the file on your system.

Once the file is downloaded, extract it into a junit.jar file. You can then add it to your project with the following steps:

  1. Create a new project on NetBeans, for example, HelloWorld.
  2. Since the new project will not have the junit.jar file, go to Properties by right-clicking on the project, as shown in the following screenshot:

  1. Go to the Libraries | Add JAR/Folder option and provide the location of where this junit.jar file is, as follows:

  1. Once done, click on Open and it will be added to your project:

  1. Now the JAR file has been added to the project, we can use the junit.jar file in an import statement. We can also import individual packages, as shown in the following screenshot:

  1. If you want to use all of the classes in framework, you just have to write the following code:
import junit.framework.*;
  1. Now, let's use the following code to print the output Hello World:
package helloworld;

/**
*
* @author admin
*/
import junit.framework.*;
public class HelloWorld {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Hello World");
}
}
  1. After running the preceding code, you should get an output similar to the following:

If you want to create a JAR file for this project, please perform the following steps:

  1. Go to Run and select Clean and Build Project (HelloWorld) to build your project:

  1. Once building the HelloWorld project is complete, the Output window will say BUILD SUCCESSFUL, as shown in the following screenshot:

  1. To check if the JAR file been created or not, go to Windows Explorer and navigate to your project's location, which you received from the previous output:

  1. Open the project folder, in our case HelloWorld, and go into the dist folder, as follows:

  1. In the dist folder, you will find the JAR file (HelloWorld.jar), which you can use and where there will be a lib folder. This will contain the junit.jar file that is being used by the HelloWorld.jar file:

This means that whenever you use any JAR files in your project, they will be stored in the lib folder of your JAR file.

Summary

In this chapter, we first looked at what the difference between supervised and unsupervised learning is, before moving on to the difference between classification and regression. We then saw how to install JDK, what the difference between JDK and JRE is, and how to install a NetBeans IDE. We also created our own JAR file by importing another JAR file into our project. In the next chapter, we'll learn how to search and explore different search algorithms.

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Leverage the power of Java libraries to build smart applications
  • Build and train deep learning models for implementing artificial intelligence
  • Learn various algorithms to automate complex tasks

Description

Artificial intelligence (AI) is increasingly in demand as well as relevant in the modern world, where everything is driven by technology and data. AI can be used for automating systems or processes to carry out complex tasks and functions in order to achieve optimal performance and productivity. Hands-On Artificial Intelligence with Java for Beginners begins by introducing you to AI concepts and algorithms. You will learn about various Java-based libraries and frameworks that can be used in implementing AI to build smart applications. In addition to this, the book teaches you how to implement easy to complex AI tasks, such as genetic programming, heuristic searches, reinforcement learning, neural networks, and segmentation, all with a practical approach. By the end of this book, you will not only have a solid grasp of AI concepts, but you'll also be able to build your own smart applications for multiple domains.

Who is this book for?

Hands-On Artificial Intelligence with Java for Beginners is for Java developers who want to learn the fundamentals of artificial intelligence and extend their programming knowledge to build smarter applications.

What you will learn

  • • Leverage different Java packages and tools such as Weka, RapidMiner, and Deeplearning4j, among others
  • • Build machine learning models using supervised and unsupervised machine learning techniques
  • • Implement different deep learning algorithms in Deeplearning4j and build applications based on them
  • • Study the basics of heuristic searching and genetic programming
  • • Differentiate between syntactic and semantic similarity among texts
  • • Perform sentiment analysis for effective decision making with LingPipe

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Aug 31, 2018
Length: 144 pages
Edition : 1st
Language : English
ISBN-13 : 9781789537550
Vendor :
Oracle
Category :
Languages :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : Aug 31, 2018
Length: 144 pages
Edition : 1st
Language : English
ISBN-13 : 9781789537550
Vendor :
Oracle
Category :
Languages :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 94.97
Machine Learning in Java
€32.99
Java Deep Learning Projects
€41.99
Hands-On Artificial Intelligence with Java for Beginners
€19.99
Total 94.97 Stars icon
Banner background image

Table of Contents

8 Chapters
Introduction to Artificial Intelligence and Java Chevron down icon Chevron up icon
Exploring Search Algorithms Chevron down icon Chevron up icon
AI Games and the Rule-Based System Chevron down icon Chevron up icon
Interfacing with Weka Chevron down icon Chevron up icon
Handling Attributes Chevron down icon Chevron up icon
Supervised Learning Chevron down icon Chevron up icon
Semi-Supervised and Unsupervised Learning Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Half star icon Empty star icon Empty star icon Empty star icon 1.3
(3 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 33.3%
1 star 66.7%
Simon Burfield Sep 27, 2018
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
This is the first book I have ever returned. I brought it to learn about deep learning which is mentioned on the front cover. Sadly, that's the only place its mentioned and it does not cover anything about deep learning. For a basic overview of AI, this should be fine.I assume the guy just never finished the book
Amazon Verified review Amazon
Sand George Ionut Nov 05, 2019
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
i don't recomand this book
Amazon Verified review Amazon
Florian Dec 14, 2018
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Das Buch schafft weder einen anstädnigen Überblick über AI, noch werden die angegeben Themen verständlich behandelt.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.