New answers tagged

0

Some good points have been said, I'm not going over those again. Just wanted to say that your code is probably meant to be used by someone else. Even if it's not, your API should reflect what your code will be working on. I would not take 2 arrays for input, but an array of 2d coordinates. Then, if for your computation it's easier to split those coordinates ...


3

Just a couple of additional points... I've not used c++17, but when performing tests against constants, consider putting the constants on the left, rather than the right. This prevents typos from having unexpected consequences. if (res = -1) changes the value of res, whereas if(-1 = res) doesn't compile. You're keeping variables in your class that seem ...


0

Consistency Your class does not seem consistent with itself. If you create a LinearReg object: x = [1, 2, 3, 4, 5] y = [2, 3, 2.5, 4, 3.5] lr = LinearReg(x, y) The constructor computes the mean of the x and y lists, and stores these for later computations. These means are fixed; you cannot add additional data points, as the mean will not be recomputed. ...


3

__MYLIB_COM_HPP is a reserved identifier, you're not allowed to use these in your code. Instead of including both <string> and <string.h>, you could also use std::strcpy(). Also, you don't need that in the header, move it to the implementation file. sizeof (char) is by definition one, because sizeof gives you the size in multiples of that of a ...


4

Toward optimized functionality and design since all crucial attributes x, y, x_mean, y_mean are initialized on LinearReg instance creation (within __init__ method) - no need to duplicate and define them as class attributes (x = [] ... y = []), those should be removed as redundant raise Error - Error is not Python exception class. Use Exception or ValueError ...


Top 50 recent answers are included