How to get the sum of least squares/error from polyfit in one dimension Python
问题 I want to do a linear regression for a scatter plot using polyfit, and I also want the residual to see how good the linear regression is. But I am unsure how I get this as it isn't possible to get the residual as an output value from polyfit since this is one dimensional. My code: p = np.polyfit(lengths, breadths, 1) m = p[0] b = p[1] yfit = np.polyval(p,lengths) newlengths = [] for y in lengths: newlengths.append(y*m+b) ax.plot(lengths, newlengths, '-', color="#2c3e50") I saw a stackoverflow