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.
-
Clone the repository:
git clone https://github.com/chocolatada21/ai-from-scratch/ -
Open the project in any Java IDE and run it.
Like any other model, it requires training data. In this example, I'll feed it values that follow the equation y = 2x:
Then, you can instantiate the model and train it using the given data:
After training, you can make predictions:
As mentioned earlier, this model uses a linear function as its activation function. The structure of the model is as follows:
It employs Mean Squared Error (MSE) to calculate the loss. The following derivatives were required for training:
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:
These values are then used to adjust the weight and bias, allowing the model to "learn":







