Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI from Scratch

A simple Java application I created to experiment with building AI from scratch, without using any frameworks. This is a small linear regression model consisting of a single neuron. It's not very smart, but I'm somewhat proud of it.

Installation

  1. Clone the repository:

    git clone https://github.com/chocolatada21/ai-from-scratch/
    
  2. Open the project in any Java IDE and run it.

Example

Like any other model, it requires training data. In this example, I'll feed it values that follow the equation y = 2x:

image

Then, you can instantiate the model and train it using the given data:

image

After training, you can make predictions:

image image

Explanation

As mentioned earlier, this model uses a linear function as its activation function. The structure of the model is as follows:

Untitled

It employs Mean Squared Error (MSE) to calculate the loss. The following derivatives were required for training:

Untitle1d

To train the model, I calculated the derivative of the loss function with respect to the weight and bias. These are represented in the code as follows:

image

These values are then used to adjust the weight and bias, allowing the model to "learn":

image

About

Basic AI experiment in Java: a single-neuron model built from scratch

Topics

Resources

Stars

6 stars

Watchers

1 watching

Forks

Contributors

Languages