Code Neural Network


You are given a pair of data points \((X, y)\), where \(X\) is an \((n, m)\) array, and \(y\) is an \((n, 1)\) array. \(y\) is continuous variable.

Write code to train a neural network model with the following specifications :

  • Input layer : Contains \(m\) nodes.
  • One hidden layer : Contains \(h\) nodes.
    • Use the ReLU activation function in the hidden layer.
  • Output layer : Contains 1 node.
    • Do not use an activation function in the output layer because this is a regression model.
Inputs
  • \(x\) : An \((n, m)\) array.
  • \(y\) : An \((n, 1)\) array.
  • input_dim : Dimension of the input layer (\(m\)).
  • hidden_dim : Dimension of the hidden layer.
  • epochs : Number of training epochs.
  • learning_rate : Step size for gradient updates.
Outputs
  • A Python class with a predict method that can be used for inference on any input \(x\).



Code Output