fertlopus / ScalaML

Testing the speed inference of classical ML algos and loss functions for the personal interest and purposes. Fell free to make changes and use it on your own

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Machine Learning Concepts using Scala


custom image


Description:

This repository contains all the code that I've wrote to test the inference speed of Gradient Descent Algorithms and Linear Regression Algos using Scala programming language. This code is just a testing purposes not a fully functional project that is ready to use out of the box.

How to install:

  • clone the repo or download as zip
  • open with IntelliJ as it is a simple IDEA project
  • Scala Build Tools (SBT)
  • Java Development Kit (JDK) >= 8.x.x
  • IDE

Navigate to the project directory and run: sbt compile

If you have changes to suggest for this repository, either:

  • submit a GitHub issue
  • submit a pull request

All the dependencies are listed in build.sbt file

Linear Regression

The LinearRegression class provides an implementation of simple linear regression that can be trained using Stochastic Gradient Descent (SGD).

Usage

To use the LinearRegression class, you must first read your data from a CSV file, separate it into features and target arrays, and then fit the model.

import machinelearning.{CSVReader, LinearRegression}

object RegressionApp {
  def main(args: Array[String]): Unit = {
    val filePath = "path/to/your/data.csv"
    val data = CSVReader.readCSV(filePath)
    val features = data.map(row => row.init.map(_.toDouble).toArray).toArray
    val target = data.map(row => row.last.toDouble).toArray

    val regression = new LinearRegression()
    regression.fit(features, target, learningRate = 0.01, epochs = 1000)
    // ...
  }
}

Classes implemented:

  • MyCSVReader - class for reading the raw (table) csv file format for further usage in machine learning algorithms
  • LinearRegression - class for linear regression algorithm using vanilla gradient descent
  • SGD - stochastic Gradient Descent class
  • NonLinearRegression - class for non linear regression

About

Testing the speed inference of classical ML algos and loss functions for the personal interest and purposes. Fell free to make changes and use it on your own


Languages

Language:Scala 100.0%