Skip to content
Advertisement

ModuleNotFoundError: No module named ‘grad’

I try to run this Neural Network script (for a regression model) There are two classes defined above. One is Standardizer class and other is Neural Net class. The Standardizer class normalizes all the values and the NeuralNet class builds the neural network that learns the data through feed forward and back propagation.

This function takes the the number of inputs, hidden units, and outputs as the three parameters.

The set_hunit function is used to either update or initiate the weights.It takes the weight as the parameter.

The Pack function packs the multiple weights of each layer into one vector. The unpack function does vice versa.

Forward pass in neural network propagates as shown below:

𝑍𝑌=ℎ(𝑋𝑙⋅𝑉)=𝑍𝑙⋅𝑊

Activation function is used to make the network non linear. We may use tanh or RBG or etc.

In the backward pass the function takes the the z values, Target values and the error as input. Based on the delta value, the weights and the bias are updated accoringly. This method returns the weight vector packed together of that particualr layer. Below are the functions that are excecuted during backward pass.

𝑉𝑊←𝑉+𝛼ℎ1𝑁1𝐾𝑋𝑙⊤((𝑇−𝑌)𝑊⊤⊙(1−𝑍2))←𝑊+𝛼𝑜1𝑁1𝐾𝑍𝑙⊤(𝑇−𝑌)

The train function takes the feautures and the target as the input. The gradientf unpacks the weights,proceeds with the forward pass by calling forward function. Now error is calculated using results of forward pass. Now back propagation is proceeded by calling backward function with parameters as error, Z, T(Target), _lambda.

The optimtarget function tries to reduce the error by using the object function and updates the weights accordingly.

The use method is applied to the test data after training the model. Testing data is passed as parameter and it stadardizes the data. Then forward is applied on the data which returns the predictions

This shows module not found error, but I have installed grad module with pip installation

enter image description here

JavaScript

Advertisement

Answer

Try to open command prompt and type pip install grad or if you using jupyter notebook, make a new code shell and type !pip install grad before you importing it

Hope that solves your problem

Advertisement