• Complain

Nisheeth Joshi [Nisheeth Joshi] - Hands-On Artificial Intelligence with Java for Beginners

Here you can read online Nisheeth Joshi [Nisheeth Joshi] - Hands-On Artificial Intelligence with Java for Beginners full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2018, publisher: Packt Publishing, genre: Home and family. Description of the work, (preface) as well as reviews are available. Best literature library LitArk.com created for fans of good reading and offers a wide selection of genres:

Romance novel Science fiction Adventure Detective Science History Home and family Prose Art Politics Computer Non-fiction Religion Business Children Humor

Choose a favorite category and find really read worthwhile books. Enjoy immersion in the world of imagination, feel the emotions of the characters or learn something new for yourself, make an fascinating discovery.

Nisheeth Joshi [Nisheeth Joshi] Hands-On Artificial Intelligence with Java for Beginners

Hands-On Artificial Intelligence with Java for Beginners: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Hands-On Artificial Intelligence with Java for Beginners" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Build, train, and deploy intelligent applications using Java libraries

Key Features
  • 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
Book 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 youll 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
Who this book is 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.

Downloading the example code for this book You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Nisheeth Joshi [Nisheeth Joshi]: author's other books


Who wrote Hands-On Artificial Intelligence with Java for Beginners? Find out the surname, the name of the author of the book and a list of all author's works by series.

Hands-On Artificial Intelligence with Java for Beginners — read online for free the complete book (whole text) full work

Below is the text of the book, divided by pages. System saving the place of the last page read, allows you to conveniently read the book "Hands-On Artificial Intelligence with Java for Beginners" online for free, without having to search again every time where you left off. Put a bookmark, and you can go to the page where you finished reading at any time.

Light

Font size:

Reset

Interval:

Bookmark:

Make
Developing a classifier

We'll be developing a very simple, decision tree-based classifier, using the weka.classifiers package. For decision tree classification, we'll use the J48 algorithm, which is a very popular algorithm. To develop a classifier, we'll set two flags, as follows:

  • -C: Sets the confidence threshold for pruning. Its default value is 0.25.
  • -M: Sets the maximum number of instances for developing a decision tree classifier. Its default value is 2.

All of the other classifiers can be developed based on similar methods, which we'll incorporate while developing our decision tree classifier. We'll develop one more classifiera Naive Bayes classifierbased on the same mechanism that we will follow to develop our decision tree classifier.

Let's get to the code and see how to do it. We'll start by importing the following classes:

import weka.core.Instances;
import weka.core.converters.ConverterUtils.DataSource;
import weka.classifiers.trees.J48;

Now, let's move on to the following code:

public static void main(String[] args) {
// TODO code application logic here
try{
DataSource src = new DataSource("/Users/admin/Documents/NetBeansProjects/DevelopClassifier/vote.arff");
Instances dt = src.getDataSet();
dt.setClassIndex(dt.numAttributes()-1);
String[] options = new String[4];
options[0] = "-C";
options[1] = "0.1";
options[2] = "-M";
options[3] = "2";
J48 tree = new J48();
tree.setOptions(options);
tree.buildClassifier(dt);
System.out.println(tree.getCapabilities().toString());
System.out.println(tree.graph());
//NaiveBayes nb = new NaiveBayes();
}
catch(Exception e){
System.out.println("Error!!!!\n" + e.getMessage());
}

This time, we're using a vote.arff dataset, because it has a very large amount of data. It is the 1984 United States Congressional Voting Records database, which has many tuples. It includes attributes such as whether a member is handicapped. Based on these attributes, it makes a prediction on whether a person is a Democrat or a Republican.

First, we'll create an object for our dataset by using a DataSource class. Then, we'll create an Instances object, and we'll put the dataset into the Instances object. Once we have opened our dataset, we will have to tell Weka which attribute is a class attribute (which one will be used for classification). As you can see in the list of attributes in the preceding code, the class attribute is at the end. Therefore, we'll take setClassIndex; and, since the -1 attribute is the class attribute, (dt.numAttributed()-1) will get the index of that particular attribute.

We'll then create an array of Strings; and, since we need to set -C and -M, we'll initialize our String array with four elements. The first element will be -C, the second will be the threshold value, the third will be -M, and the fourth will be the number of iterations it should take. Then, we will create an object for J48. Once we have created an object for J48, we'll assign the options to J48 by using setOptions. Then, we will have to build a classifier using the dataset.

So, we will take our J48 object with its buildClassifier method, and we'll supply it with our dataset. This will create a classifier for the tree object.

Once we have done this, we can print its capabilities with the toString method. This will print the types of attributes that it can classify. Once we have done so, we can print its graph. This will give us the exact decision tree graph that it has developed, which it has also trained.

Running the code will provide the following output:

Since the first print statement was getCapabilities that has been printed The - photo 1

Since the first print statement was getCapabilities, that has been printed. The classifier has been trained, and it can incorporate Nominal, Binary, Unary, and a list of some more attributes that it can train itself on. digraph J48Tree in the output is the tree that was generated with those attributes. That is how we can develop a classifier.

Suppose that we want to train one more classifier, using Naive Bayes; first, we will have to incorporate the NaiveBayes class that is available in the bayes package of the weka.classifiers class:

import weka.classifiers.bayes.NaiveBayes;

Next, we will create an object, nb, for NaiveBayes, and pass the dt dataset to the buildClassifier method of nb:

NaiveBayes nb = new NaiveBayes();
nb.buildClassifier(dt);
System.out.println(nb.getCapabilities().toString());

When this has finished, the classifier will be trained, and we will be able to print its capabilities.

Run the code again to get the following output:

In the preceding screenshot you can see that the Naive Bayes classifier has - photo 2

In the preceding screenshot, you can see that the Naive Bayes classifier has been trained, and it has provided the attributes upon which the classifier can be trained.

Self-training and co-training machine learning models

You will now learn how to develop semi-supervised models.

The very first thing that we'll do is download a package for semi-supervised learning, then we will create a classifier for a semi-supervised model.

Reading and writing datasets

We will now look at how to read and write a dataset. Let's get to our Java code. Create a project and name it Datasets. Now, import the weka.jar file, as performed in the previous section. Once we have the weka.jar file available, we can read the core, Instance interfaces, ArffSaver, DataSource, and io.File packages, as shown in the following screenshot:

We will start with DataSource DataSource is a class that helps us to open a - photo 3

We will start with DataSource. DataSource is a class that helps us to open a dataset file that is available in Weka. By default, Weka works with ARFF files; see the following code:

DataSource src = new DataSource("/Users/admin/wekafiles/data/weather.numeric.arff");
Instances dt= src.getDataSet();
System.out.println(dt.toSummaryString());
ArffSaver as = new ArffSaver();

As we can see in the preceding code, we created an object for DataSource and provided a path to the ARFF file that we need to open. This will only provide a path to an ARFF file; it will not open it. In the working memory, there is a class called Instances, and we have created an object, dt, for the Instances class. We'll call the getDataSet method with the object of DataSource and src. This will open that particular dataset into memory in the dt object. We can print whatever is available in that particular dataset by using the toSummaryString method. Once it has been read and opened, we can write it onto the hard disk by using the ArffSaver class. We will create an object (as) for it, as follows:

as.setInstances(dt);

This will only assign all of the data that is available with dt object to the as object. It will not save it, as of right now. Now, we have to give a name to the dataset; so, we will call the setFile method and we'll provide weather.arff as filename to our dataset using a File object :

as.setFile(new File("weather.arff"));

Now, the dataset has been given a name, but it still has not been saved in the memory. We will now call a writeBatch method, as follows:

as.writeBatch();

Finally, everything will get saved to the memory with the filename (weather.arff). When we execute the code, we will see the following output:

It has the Relation Name as weather which has 14 instances and 5 attributes - photo 4

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Hands-On Artificial Intelligence with Java for Beginners»

Look at similar books to Hands-On Artificial Intelligence with Java for Beginners. We have selected literature similar in name and meaning in the hope of providing readers with more options to find new, interesting, not yet read works.


Reviews about «Hands-On Artificial Intelligence with Java for Beginners»

Discussion, reviews of the book Hands-On Artificial Intelligence with Java for Beginners and just readers' own opinions. Leave your comments, write what you think about the work, its meaning or the main characters. Specify what exactly you liked and what you didn't like, and why you think so.