Posts

Showing posts from June, 2024

A Single Layer Perceptron for Regression: Part 6

 Error Resolved The adjusted r-squared value was not working properly because the number of predictors passed to it in the epochs function was wrong. It was being passes the number of inputs instead of the number of predictors i.e. the number of rows instead of the number of columns. New Function Added add_bias :  This function adds the bias constant value to each row of the inputs. Parameters :  (1) inputs(numpy array (m,n)): All the predictors.                       (2) bias_value(float) : The constant that the bias should be equal to. By default, its                                   value is 1.                      Next Step: -  Extending this code so that multiple neurons/layers can be created.

A Single Layer Perceptron for Regression: Part 5

     New Function created: calculate_rsquare :  This function calculates the R-square value. This value helps understand the accuracy of the model. It is used for both single and multiple linear regression. However, adjusted R-square works better for the latter.   Parameters :  (1) predicted_output(numpy array (m,1)): Predicted output values.                       (2) actual_output(numpy array (m,1)) : The original output values.                       (3) num_of_predictor_variables (int): Number of predictor variables.                       (4) mean_of_output(float or string) : The mean of the actual output values. If it is                                          ...

A Single Layer Perceptron for Regression: Part 4

 Testing - Observations, Rectifications, and Plans 1) Adding a second condition to end epochs: Till now, the only condition in the loop was that the difference between the errors of 2 consecutive epochs had to be within the threshold value. This created an issue when the error value kept going up with each epoch. I, hence, added another condition that checks if the current value is 0.2 values higher than the previous error. If yes, then the loop breaks. Reason to use 0.2: While experimenting with the dataset, 0.2 gave the best results. I hope to:      a) Change 0.2 to an argument.      b) Experiment with more datasets to find a more appropriate value to use. 2)    Need to add Accuracy metric: Currently, the code, only shows the error. However, I would like to add the R squared value as a metric to see how good the model is w.r.t. accuracy. Code   The new version of the code can be found on this link:  https://github.com/HridayaAnnun...