Book Image

Clojure Data Analysis Cookbook

By : Eric Rochester
Book Image

Clojure Data Analysis Cookbook

By: Eric Rochester

Overview of this book

<p>Data is everywhere and it's increasingly important to be able to gain insights that we can act on. Using Clojure for data analysis and collection, this book will show you how to gain fresh insights and perspectives from your data with an essential collection of practical, structured recipes.<br /><br />"The Clojure Data Analysis Cookbook" presents recipes for every stage of the data analysis process. Whether scraping data off a web page, performing data mining, or creating graphs for the web, this book has something for the task at hand.<br /><br />You'll learn how to acquire data, clean it up, and transform it into useful graphs which can then be analyzed and published to the Internet. Coverage includes advanced topics like processing data concurrently, applying powerful statistical techniques like Bayesian modelling, and even data mining algorithms such as K-means clustering, neural networks, and association rules.</p>
Table of Contents (18 chapters)
Clojure Data Analysis Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Scaling variables to simplify variable relationships


We don't always work with numbers as they are. For example, population is often given in thousands. In this recipe, we'll scale some values to make them easier to work with. In fact, some algorithms work better with scaled data. For instance, linear regression models are sometimes able to fit the data better after it has been scaled logarithmically.

Getting ready

We'll use the following dependencies in our project.clj file:

:dependencies [[org.clojure/clojure "1.4.0"]
               [incanter "1.4.1"]]

And we'll use the following namespaces in our script or REPL:

(require
  '[incanter.core :asi]
  'incanter.io
  '[incanter.charts :as c])

For data, we'll use the census data that we did in the Differencing variables to show changes recipe.

(def data-file "data/all_160_in_51.P3.csv")

How to do it…

In this recipe, we'll scale the data in two ways.

  1. Before we start scaling anything, we'll read in the data and sort it.

    (def data
      (i/$order :POP100 :asc...