Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
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

By Nisheeth Joshi
$25.99
Book Aug 2018 144 pages 1st Edition
eBook
$21.99 $14.99
Print
$25.99
Subscription
$15.99 Monthly
eBook
$21.99 $14.99
Print
$25.99
Subscription
$15.99 Monthly

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


Publication date : Aug 31, 2018
Length 144 pages
Edition : 1st Edition
Language : English
ISBN-13 : 9781789537550
Vendor :
Oracle
Category :
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Artificial Intelligence with Java for Beginners

Chapter 1. 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!

 

Note

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.jarfile in animportstatement.We can alsoimportindividual 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.

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

What do you get with Print?

Product feature icon Instant access to your digital eBook copy whilst your Print order is Shipped
Product feature icon Black & white paperback book shipped to your address
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Buy Now

Product Details


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

Table of Contents

14 Chapters
Title Page Chevron down icon Chevron up icon
Copyright and Credits Chevron down icon Chevron up icon
Packt Upsell Chevron down icon Chevron up icon
Contributors Chevron down icon Chevron up icon
Preface Chevron down icon Chevron up icon
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
Index Chevron down icon Chevron up icon

Customer reviews

Filter icon Filter
Top Reviews
Rating distribution
Empty star icon Empty star icon Empty star icon Empty star icon Empty star icon 0
(0 Ratings)
5 star 0%
4 star 0%
3 star 0%
2 star 0%
1 star 0%

Filter reviews by


No reviews found
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is the delivery time and cost of print book? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela
What is custom duty/charge? Chevron down icon Chevron up icon

Customs duty are charges levied on goods when they cross international borders. It is a tax that is imposed on imported goods. These duties are charged by special authorities and bodies created by local governments and are meant to protect local industries, economies, and businesses.

Do I have to pay customs charges for the print book order? Chevron down icon Chevron up icon

The orders shipped to the countries that are listed under EU27 will not bear custom charges. They are paid by Packt as part of the order.

List of EU27 countries: www.gov.uk/eu-eea:

A custom duty or localized taxes may be applicable on the shipment and would be charged by the recipient country outside of the EU27 which should be paid by the customer and these duties are not included in the shipping charges been charged on the order.

How do I know my custom duty charges? Chevron down icon Chevron up icon

The amount of duty payable varies greatly depending on the imported goods, the country of origin and several other factors like the total invoice amount or dimensions like weight, and other such criteria applicable in your country.

For example:

  • If you live in Mexico, and the declared value of your ordered items is over $ 50, for you to receive a package, you will have to pay additional import tax of 19% which will be $ 9.50 to the courier service.
  • Whereas if you live in Turkey, and the declared value of your ordered items is over € 22, for you to receive a package, you will have to pay additional import tax of 18% which will be € 3.96 to the courier service.
How can I cancel my order? Chevron down icon Chevron up icon

Cancellation Policy for Published Printed Books:

You can cancel any order within 1 hour of placing the order. Simply contact customercare@packt.com with your order details or payment transaction id. If your order has already started the shipment process, we will do our best to stop it. However, if it is already on the way to you then when you receive it, you can contact us at customercare@packt.com using the returns and refund process.

Please understand that Packt Publishing cannot provide refunds or cancel any order except for the cases described in our Return Policy (i.e. Packt Publishing agrees to replace your printed book because it arrives damaged or material defect in book), Packt Publishing will not accept returns.

What is your returns and refunds policy? Chevron down icon Chevron up icon

Return Policy:

We want you to be happy with your purchase from Packtpub.com. We will not hassle you with returning print books to us. If the print book you receive from us is incorrect, damaged, doesn't work or is unacceptably late, please contact Customer Relations Team on customercare@packt.com with the order number and issue details as explained below:

  1. If you ordered (eBook, Video or Print Book) incorrectly or accidentally, please contact Customer Relations Team on customercare@packt.com within one hour of placing the order and we will replace/refund you the item cost.
  2. Sadly, if your eBook or Video file is faulty or a fault occurs during the eBook or Video being made available to you, i.e. during download then you should contact Customer Relations Team within 14 days of purchase on customercare@packt.com who will be able to resolve this issue for you.
  3. You will have a choice of replacement or refund of the problem items.(damaged, defective or incorrect)
  4. Once Customer Care Team confirms that you will be refunded, you should receive the refund within 10 to 12 working days.
  5. If you are only requesting a refund of one book from a multiple order, then we will refund you the appropriate single item.
  6. Where the items were shipped under a free shipping offer, there will be no shipping costs to refund.

On the off chance your printed book arrives damaged, with book material defect, contact our Customer Relation Team on customercare@packt.com within 14 days of receipt of the book with appropriate evidence of damage and we will work with you to secure a replacement copy, if necessary. Please note that each printed book you order from us is individually made by Packt's professional book-printing partner which is on a print-on-demand basis.

What tax is charged? Chevron down icon Chevron up icon

Currently, no tax is charged on the purchase of any print book (subject to change based on the laws and regulations). A localized VAT fee is charged only to our European and UK customers on eBooks, Video and subscriptions that they buy. GST is charged to Indian customers for eBooks and video purchases.

What payment methods can I use? Chevron down icon Chevron up icon

You can pay with the following card types:

  1. Visa Debit
  2. Visa Credit
  3. MasterCard
  4. PayPal
What is the delivery time and cost of print books? Chevron down icon Chevron up icon

Shipping Details

USA:

'

Economy: Delivery to most addresses in the US within 10-15 business days

Premium: Trackable Delivery to most addresses in the US within 3-8 business days

UK:

Economy: Delivery to most addresses in the U.K. within 7-9 business days.
Shipments are not trackable

Premium: Trackable delivery to most addresses in the U.K. within 3-4 business days!
Add one extra business day for deliveries to Northern Ireland and Scottish Highlands and islands

EU:

Premium: Trackable delivery to most EU destinations within 4-9 business days.

Australia:

Economy: Can deliver to P. O. Boxes and private residences.
Trackable service with delivery to addresses in Australia only.
Delivery time ranges from 7-9 business days for VIC and 8-10 business days for Interstate metro
Delivery time is up to 15 business days for remote areas of WA, NT & QLD.

Premium: Delivery to addresses in Australia only
Trackable delivery to most P. O. Boxes and private residences in Australia within 4-5 days based on the distance to a destination following dispatch.

India:

Premium: Delivery to most Indian addresses within 5-6 business days

Rest of the World:

Premium: Countries in the American continent: Trackable delivery to most countries within 4-7 business days

Asia:

Premium: Delivery to most Asian addresses within 5-9 business days

Disclaimer:
All orders received before 5 PM U.K time would start printing from the next business day. So the estimated delivery times start from the next day as well. Orders received after 5 PM U.K time (in our internal systems) on a business day or anytime on the weekend will begin printing the second to next business day. For example, an order placed at 11 AM today will begin printing tomorrow, whereas an order placed at 9 PM tonight will begin printing the day after tomorrow.


Unfortunately, due to several restrictions, we are unable to ship to the following countries:

  1. Afghanistan
  2. American Samoa
  3. Belarus
  4. Brunei Darussalam
  5. Central African Republic
  6. The Democratic Republic of Congo
  7. Eritrea
  8. Guinea-bissau
  9. Iran
  10. Lebanon
  11. Libiya Arab Jamahriya
  12. Somalia
  13. Sudan
  14. Russian Federation
  15. Syrian Arab Republic
  16. Ukraine
  17. Venezuela