Giter VIP home page Giter VIP logo

javamlr's Introduction

Multiple linear regression in Java

Implementation of multiple linear regression in Java for continuous data, fitting the parameters both using gradient descent and the closed-form normal equation method. Developed from scratch, excluding the use of the Apache Commons Math
library for matrix operations.

Data source: Concrete compressive strength, UCI Machine Learning Repository

The model is fit in the class Fit, predicting the feature specified by the dependent parameter using all other features, in one of two methods:

  • Fit.gradientDescent, which fits the parameters using batch gradient descent with a learning rate specified by the alpha parameter. To speed up convergence, helper methods are used to standardise data.
  • Fit.normalEquation, which fits the parameters in closed form using the normal equation method. Matrix operations are done using the Apache Commons Math library. As expected, this is dramatically faster than gradient descent over the sample data.

Once the model is fit, a Model object is returned. The intercept and parameters are stored as key-value pairs and the R-squared value and name of the dependent variable are accessible as public fields. The method predict() takes an Observation object with dimensions matching the training data and returns a prediction for the dependent variable, while toString() gives the R-squared value and parameters.

In the main method of javamlr.MultipleLinearRegression, a model is fit on our sample data using both methods to demonstrate the similarity of their fit and the difference in speed. To demonstrate the Model.predict() method, some arbitrary rows of the dataset are then predicted.

Instructions

  • From the root directory, compile with: javac -classpath lib/* -d . src/*.java
  • The main program can then be executed from the root directory using: java -classpath .:lib/* javamlr.MultipleLinearRegression (for Windows, replace .:lib/* with .;lib/*)

javamlr's People

Contributors

markgaynor avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.