• Complain

Rushdi Shams [Shams - Java Data Science Cookbook

Here you can read online Rushdi Shams [Shams - Java Data Science Cookbook full text of the book (entire story) in english for free. Download pdf and epub, get meaning, cover and reviews about this ebook. year: 2017, publisher: Packt Publishing Ltd, genre: Computer. 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.

Rushdi Shams [Shams Java Data Science Cookbook

Java Data Science Cookbook: summary, description and annotation

We offer to read an annotation, description, summary or preface (depends on what the author of the book "Java Data Science Cookbook" wrote himself). If you haven't found the necessary information about the book — write in the comments, we will try to find it.

Recipes to help you overcome your data science hurdles using JavaAbout This BookThis book provides modern recipes in small steps to help an apprentice cook become a master chef in data scienceUse these recipes to obtain, clean, analyze, and learn from your dataLearn how to get your data science applications to production and enterprise environments effortlesslyWho This Book Is ForThis book is for Java developers who are familiar with the fundamentals of data science and want to improve their skills to become a pro.What You Will LearnFind out how to clean and make datasets ready so you can acquire actual insights by removing noise and outliersDevelop the skills to use modern machine learning techniques to retrieve information and transform data to knowledge. retrieve information from large amount of data in text format.Familiarize yourself with cutting-edge techniques to store and search large volumes of data and retrieve information from large amounts of data in text formatDevelop basic skills to apply big data and deep learning technologies on large volumes of dataEvolve your data visualization skills and gain valuable insights from your dataGet to know a step-by-step formula to develop an industry-standard, large-scale, real-life data productGain the skills to visualize data and interact with users through data insightsIn DetailIf you are looking to build data science models that are good for production, Java has come to the rescue. With the aid of strong libraries such as MLlib, Weka, DL4j, and more, you can efficiently perform all the data science tasks you need to.This unique book provides modern recipes to solve your common and not-so-common data science-related problems. We start with recipes to help you obtain, clean, index, and search data. Then you will learn a variety of techniques to analyze, learn from, and retrieve information from data. You will also understand how to handle big data, learn deeply from data, and visualize data.Finally, you will work through unique recipes that solve your problems while taking data science to production, writing distributed data science applications, and much morethings that will come in handy at work.Style and approachThis book contains short yet very effective recipes to solve most common problems. Some recipes cater to very specific, rare pain points. The recipes cover different data sets and work very closely to real production environments

Rushdi Shams [Shams: author's other books


Who wrote Java Data Science Cookbook? Find out the surname, the name of the author of the book and a list of all author's works by series.

Java Data Science Cookbook — 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 "Java Data Science Cookbook" 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
Chapter 1. Obtaining and Cleaning Data

In this chapter, we will cover the following recipes:

  • Retrieving all file names from hierarchical directories using Java
  • Retrieving all file names from hierarchical directories using Apache Commons IO
  • Reading contents from text files all at once using Java 8
  • Reading contents from text files all at once using Apache Commons IO
  • Extracting PDF text using Apache Tika
  • Cleaning ASCII text files using Regular Expressions
  • Parsing Comma Separated Value files using Univocity
  • Parsing Tab Separated Value files using Univocity
  • Parsing XML files using JDOM
  • Writing JSON files using JSON.simple
  • Reading JSON files using JSON.simple
  • Extracting web data from a URL using JSoup
  • Extracting web data from a website using Selenium Webdriver
  • Reading table data from MySQL database
Introduction

Every data scientist needs to deal with data that is stored on disks in several formats, such as ASCII text, PDF, XML, JSON, and so on. Also, data can be stored in database tables. The first and foremost task for a data scientist before doing any analysis is to obtain data from these data sources and of these formats, and apply data-cleaning techniques to get rid of noises present in them. In this chapter, we will see recipes to accomplish this important task.

We will be using external Java libraries (Java archive files or simply JAR files) not only for this chapter but throughout the book. These libraries are created by developers or organizations to make everybody's life easier. We will be using Eclipse IDE for code development, preferably on the Windows platform, and execution throughout the book. Here is how you can include any external JAR file, and in many recipes, where I instruct you to include external JAR files into your project, this is what you need to do.

You can add a JAR file in a project in Eclipse by right-clicking on the Project | Build Path | Configure Build Path . Under the Libraries tab, click on Add External JARs... , and select the external JAR file(s) that you are going to use for a particular project:

Retrieving all filenames from hierarchical directories using Java This recipe - photo 1
Retrieving all filenames from hierarchical directories using Java

This recipe (and the following) is for the data scientist who wants to retrieve the file paths and names (for some future analysis) from a complex directory structure that contains numerous directories and files inside a root directory.

Getting ready

In order to perform this recipe, we will require the following:

  1. Create directories within directories (as many layers as you want).
  2. Create text files in some of these directories while leaving some directories empty for more excitement.
How to do it...
  1. We are going to create a static method that takes a File argument, which is eventually the root directory or the directory to start with. The method will return a set of files that are found within this root directory (and in all other subsequent directories): public static Set listFiles(File rootDir) {
  2. First, create a HashSet that will contain the file information: Set fileSet = new HashSet();
  3. Once the HashSet is created, we need to check whether the root directory or the directories within it are null. For such cases, we do not need to proceed further: if (rootDir == null || rootDir.listFiles() == null){ return fileSet; }
  4. We consider one directory (or file) from the root directory at a time and check whether we are dealing with a file or with a directory. In the case of a file, we add that to our HashSet. In the case of a directory, we recursively call this method again by sending the path and name of the directory: for (File fileOrDir : rootDir.listFiles()) { if (fileOrDir.isFile()){ fileSet.add(fileOrDir); } else{ fileSet.addAll(listFiles(fileOrDir)); } }
  5. Finally, we return the HashSet to the caller of this method: return fileSet; }

    The complete method, with the class and the driver method to run it, is as follows:

    import java.io.File; import java.util.HashSet; import java.util.Set; public class TestRecursiveDirectoryTraversal { public static void main(String[] args){ System.out.println(listFiles(new File("Path for root directory")).size()); } public static Set listFiles(File rootDir) { Set fileSet = new HashSet(); if(rootDir == null || rootDir.listFiles()==null){ return fileSet; } for (File fileOrDir : rootDir.listFiles()) { if (fileOrDir.isFile()){ fileSet.add(fileOrDir); } else{ fileSet.addAll(listFiles(fileOrDir)); } } return fileSet; } }
Note

Note the use of HashSet to store the paths and names of the files. This means that we will not have any duplicates since the Set data structures in Java do not contain duplicate entries.

Retrieving all filenames from hierarchical directories using Apache Commons IO

Listing of file names in hierarchical directories can be done recursively as demonstrated in the previous recipe. However, this can be done in a much easier and convenient way and with less coding using the Apache Commons IO library.

Getting ready

In order to perform this recipe, we will require the following:

  1. In this recipe, we will be using a Java library from Apache named Commons IO. Throughout the book, we will be using version 2.5. Download the JAR file of your choice from here: https://commons.apache.org/proper/commons-io/download_io.cgi
  2. Include the JAR file in your project an external JAR in Eclipse.
How to do it...
  1. Create a method that takes the root directory in the hierarchy of directories as input: public void listFiles(String rootDir){
  2. Create a file object with the root directory name: File dir = new File(rootDir);
  3. The FileUtils class of the Apache Commons library contains a method named listFiles(). Use this method to retrieve all the file names, and put the names in a list variable with generics. Use TrueFileFilter.INSTANCE to match all directories: List files = (List) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE);
  4. The file names can be displayed on the standard output as follows. As we now have the names in a list, we have a means to process the data in these files further: for (File file : files) { System.out.println("file: " + file.getAbsolutePath()); }
  5. Close the method: }

    The method in this recipe, the class for it, and the driver method to run it are as follows:

    import java.io.File; import java.util.List; import org.apache.commons.io.FileUtils; import org.apache.commons.io.filefilter.TrueFileFilter; public class FileListing{ public static void main (String[] args){ FileListing fileListing = new FileListing(); fileListing.listFiles("Path for the root directory here"); } public void listFiles(String rootDir){ File dir = new File(rootDir); List files = (List) FileUtils.listFiles(dir, TrueFileFilter.INSTANCE, TrueFileFilter.INSTANCE); for (File file : files) { System.out.println("file: " + file.getAbsolutePath()); } }
Tip

If you want to list files with some particular extensions, there is a method in Apache Commons library called

Next page
Light

Font size:

Reset

Interval:

Bookmark:

Make

Similar books «Java Data Science Cookbook»

Look at similar books to Java Data Science Cookbook. 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 «Java Data Science Cookbook»

Discussion, reviews of the book Java Data Science Cookbook 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.