prnicolas / ScalaMl

Project, source code and data files for 1st edition "Scala for Machine Learning"
http://www.scalaformachinelearning.com
151 stars 86 forks source link

Scala for Machine Learning Version 0.99.1
Copyright Patrick Nicolas All rights reserved 2013-2016
=================================================================

Overview
Latest release
Documentation
Minimum requirements
History
Project
installation
build
Run examples
Persistent models and configurations
Appendix

Overview

The source code provides software developers with a broad overview of the difference in machine learning algorithms. The reader is expected to have a good grasp of the Scala programming language along with some knowledge in basic statistics. Experience in data mining and machine learning is not a pre-requisite.

Source code guidelines are defined in the companion document SourceCodeGuide.html

The examples are related to investment portfolio management and trading strategies. For the readers interested either in mathematics or the techniques implemented in this library, I strongly recommend the following readings:

The real-world examples, related to financial and market analysis, used for the sole purpose of illustrating the machine learning techniques. They do not constitute a recommendation or endorsement of any specific investment management or trading techniques.
The Appendix contains an introduction to the basic concepts of investment and trading strategies as well as technical analysis of financial markets.

Latest release

Here is the list of changes introduced in version 0.99.1 of "Scala for Machine Learning"


Note: The implementation of Cholesky decomposition for the adjustment (or correction) of the state x of the Kalman filter using the measured value (z may throw an NonSymmetricMatrixException depending on the input value. The problem is caused by the default values used to validate that the matrix is indeed symmetric.
The problem is fixed in version 3.6:
"A call to "KalmanFilter#correct(...)" may have resulted in "NonSymmetricMatrixException" as the internally used matrix inversion method was using a too strict symmetry check. Fixes MATH-1062."

Documentation

The best approach to learn about any particular learning algorithm is to

Minimum Requirements

Hardware: 2 CPU core with 4 Gbytes RAM for small datasets to build and run examples.
4 CPU Core and 8+ Gbytes RAM for datasets of size 75,000 or larger and/or with 50 features set or larger
Operating system: None
Software: JDK 1.7.0_45 or 1.8.0_25, Scala 2.10.4 (for Apache Spark) or 2.11.2 (for Akka) and SBT 0.13+ (see installation section for deployment.

History

0.99.1 (12/17/2015)

See Latest release

0.99 (10/30/2015)

0.98.2 (03/19/2015)

0.98.1 (02/14/2015)

0.98 (12/02/2014)

0.97 (06/12/2014)

Initial implementation

Project Components

Directory structure of the source code library for Scala for Machine Learning:
Source code

Directory structure of the source code of the examples for Scala for Machine Learning:
Examples

Installation and Build

Installation

The installation and build workflow is described in the following diagram:
Installation and build
Eclipse The Scala for Machine Learning library is compatible with Eclipse Scala IDE 3.0
Specify link to the source in Project/properties/Java Build Path/Source. The two links should be project_name/src/main/scala and project_name/src/test/scala
Add the jars required to build and execute the code within Eclipse Project/properties/Java Build Path/Add External Jarsas declared in the project_name/.classpath
Update the JVM heap parameters in eclipse.ini file as -Xms512m -Xmx8192m or the maximum allowed on your specific machine.

Build

build.sbt

The Simple Build Too (SBT) has to be used to build the library from the source code using the build.sbt file in the root directory
Executing the examples/test in Scala for Machine Learning require sufficient JVM Heap memory (~2G):
in sbt/conf/sbtconfig.text set Xmx to 2058m or higher, -XX:MaxPermSize to 512m or higher i.e. -Xmx4096m -Xms512m -XX:MaxPermSize=512m

Build script for Scala for Machine Learning:
To build the Scala for Machine Learning library package
$(ROOT)/sbt clean publish-local
To build the package including test and resource files
$(ROOT)/sbt clean package
To generate scala doc for the library
$(ROOT)/sbt doc
To generate scala doc for the examples
$(ROOT)/sbt test:doc
To generate report for compliance to Scala style guide:
$(ROOT)/sbt scalastyle
To compile all examples:
$(ROOT)/sbt test:compile

Maven

A simple pom.xml is available to build the library and execute the test cases:
$(ROOT)/mvn compile to compile the library
$(ROOT)/mvn test to compile and run the examples

Run examples

Note: As the implementation evolves over-time, few test examples may differ from the original test described in the book. The implementation of the algorithm is not expected to change.

Examples in a chapter

To run the examples of a particular chapter (i.e. Chapter 4)
$(ROOT)/$sbt
>test-only org.scalaml.app.chap4.Chap4

All examples

To run all examples with output configuration:
$(ROOT)/sbt "test:run options" where options is a list of possible outputs

$(ROOT)/sbt "test:run log chart" write test results into a log and charts
$(ROOT)/sbt test:run write test results into the standard output and the charts.
$(ROOT)/mvn test to compile and run the examples

Persistent models and configurations

The package object org.scalaml.core.Design provide the trait (or skeleton implementation) of the persistent model Design.Model and configuration Design.Config.
The persistency mechanisms is implemented for a couple of supervised learning models only for illustration purpose. The reader should be able to implement the persistency for configuration and models for all relevant learning algorithms using the template operator << and >>

Appendix

The examples have been built and tested with the following libraries:
Java libraries
CRF-Trove_3.0.2.jar
LBFGS.jar
colt.jar
CRF-1.1.jar
commons-math3-3.5.jar
libsvm_sml-3.18.jar
jfreechart-1.0.17/lib/jcommon-1.0.21.jar
jfreechart-1.0.17/lib/servlets.jar
junit-4.11.jar
jfreechart-1.0.17/lib/jfreechart-1.0.17.jar
Scala 2.10 related libraries
com.typesafe/config/1.2.1/bundles/config.jar
akka-actor_2.10-2.2.3.jar
scalatest_2.1.16.jar
spark-assembly-1.5.0-hadoop2.4.0.jar
Scala 2.11. related libraries
com.typesafe/config/1.2.2/bundles/config.jar
scalatest_2.2.2.jar
akka-actor_2.11-2.3.4.jar
spark-assembly-1.5.0-hadoop2.4.0.jar