Print only 2 significant figures of regression results.

This commit is contained in:
2025-04-23 18:42:37 -07:00
parent 721a38435b
commit 7d82e4c588

View File

@@ -178,19 +178,20 @@
"\n", "\n",
" model.fit(X_train, y_train)\n", " model.fit(X_train, y_train)\n",
" y_pred = model.predict(X_test)\n", " y_pred = model.predict(X_test)\n",
"\n", " \n",
" m = model.coef_[0][0]\n",
" b = model.intercept_[0]\n",
" print(\"+----------------------+\")\n", " print(\"+----------------------+\")\n",
" print(\"%s regression line for %s\" % (line_color, self.language))\n", " print(\"%s regression line for %s\" % (line_color, self.language))\n",
" print(\"coefficient =\", model.coef_)\n", " print(\"coefficient = %0.2f\" % m)\n",
" print('intercept=', model.intercept_)\n", " print('intercept = %0.2f' % b)\n",
" rmse = root_mean_squared_error(y_test, y_pred)\n", " rmse = root_mean_squared_error(y_test, y_pred)\n",
" print(\"rmse = \", rmse)\n", " print(\"rmse = %0.2f\" % rmse)\n",
" r2 = r2_score(y_test, y_pred)\n", " r2 = r2_score(y_test, y_pred)\n",
" print(\"r2 score = \", r2)\n", " print(\"r2 score = %0.2f\" % r2)\n",
" print(\"sample predictions:\")\n", " print(\"sample predictions:\")\n",
" print(y_pred[3:6])\n", " print(y_pred[3:6])\n",
" print(\"+----------------------+\")\n", " print(\"+----------------------+\")\n",
" b = model.intercept_[0]\n",
"\n", "\n",
" plt.figure(self.canvas)\n", " plt.figure(self.canvas)\n",
" plt.plot(X_test, y_pred, color=line_color, label='Regression Line')\n", " plt.plot(X_test, y_pred, color=line_color, label='Regression Line')\n",
@@ -247,7 +248,7 @@
"\n", "\n",
"* The income of a data professional can either increase by 2,000 per year (red) or 10,000 per year (cyan).\n", "* The income of a data professional can either increase by 2,000 per year (red) or 10,000 per year (cyan).\n",
"\n", "\n",
"* For both models, the r2 score ranges from poor to moderate = 0.20 - 0.37 depending on the random number. The variability not explained by the model could be the result of the fields such as advertising, finance, or bio/medical technology.\n", "* For both models, the r2 score ranges from poor to moderate = 0.20 - 0.37 depending on the random number. The variability not explained by the model could be the result of different fields that employ dats scientists/analysts/engineers such as finance, bio/med, or advertising.\n",
"\n", "\n",
"* For any given point in the career, the model is off by 39,000 or 42,000 dollars.\n", "* For any given point in the career, the model is off by 39,000 or 42,000 dollars.\n",
"\n", "\n",