I found that the accepted answer had some malfunctioning issues that would generally require editing outside the recommended etiquette to change the messages . So, here is the solution for calculating the standard error estimate for the coefficients obtained using the linear model (using the unbiased estimate proposed here ):
# preparation X = np.concatenate((np.ones(TST.shape[0], 1)), TST), axis=1) y_hat = clf.predict(TST).T m, n = X.shape
Note that we must add the unit column to the TST since the original message used linear_model.LinearRegression so that it matches the interception terms. In addition, we need to calculate the mean square error (MSE), as in ANOVA . That is, we need to divide the sum of squared errors (SSE) by the degrees of freedom for the error, i.e. Df_error = df_observations - df_features.
The resulting coef_SE_est array contains standard estimates of interception errors and all other coefficients in coef_SE_est[0] and coef_SE_est[1:] respectively. To print them you can use
print('intercept: coef={:.4f} / std_err={:.4f}'.format(clf.intercept_[0], coef_SE_est[0])) for i, coef in enumerate(clf.coef_[0,:]): print('x{}: coef={:.4f} / std_err={:.4f}'.format(i+1, coef, coef_SE_est[i+1]))
source share