Machine learning – Linear regression using batch gradient descent

The error is very simple. Your delta declaration should be inside the first for loop. Every time you accumulate the weighted differences between the training sample and output, you should start accumulating from the beginning. By not doing this, what you’re doing is accumulating the errors from the previous iteration which takes the error of … Read more

Spark mllib predicting weird number or NaN

The problem is that LinearRegressionWithSGD uses stochastic gradient descent (SGD) to optimize the weight vector of your linear model. SGD is really sensitive to the provided stepSize which is used to update the intermediate solution. What SGD does is to calculate the gradient g of the cost function given a sample of the input points … Read more

Cost function in logistic regression gives NaN as a result

There are two possible reasons why this may be happening to you. The data is not normalized This is because when you apply the sigmoid / logit function to your hypothesis, the output probabilities are almost all approximately 0s or all 1s and with your cost function, log(1 – 1) or log(0) will produce -Inf. … Read more

Why should weights of Neural Networks be initialized to random numbers? [closed]

Breaking symmetry is essential here, and not for the reason of performance. Imagine first 2 layers of multilayer perceptron (input and hidden layers): During forward propagation each unit in hidden layer gets signal: That is, each hidden unit gets sum of inputs multiplied by the corresponding weight. Now imagine that you initialize all weights to … Read more

How to calculate optimal batch size

From the recent Deep Learning book by Goodfellow et al., chapter 8: Minibatch sizes are generally driven by the following factors: Larger batches provide a more accurate estimate of the gradient, but with less than linear returns. Multicore architectures are usually underutilized by extremely small batches. This motivates using some absolute minimum batch size, below … Read more

Cost function training target versus accuracy desired goal

How can we train a neural network so that it ends up maximizing classification accuracy? I’m asking for a way to get a continuous proxy function that’s closer to the accuracy To start with, the loss function used today for classification tasks in (deep) neural nets was not invented with them, but it goes back … Read more

What is `weight_decay` meta parameter in Caffe?

The weight_decay meta parameter govern the regularization term of the neural net. During training a regularization term is added to the network’s loss to compute the backprop gradient. The weight_decay value determines how dominant this regularization term will be in the gradient computation. As a rule of thumb, the more training examples you have, the … Read more