ibnummuhammad
commited on
Commit
•
29f08a8
1
Parent(s):
5ac2d9e
Fix code
Browse files- coal-price-forecast.ipynb +10 -41
coal-price-forecast.ipynb
CHANGED
@@ -1506,7 +1506,7 @@
|
|
1506 |
"name": "stderr",
|
1507 |
"output_type": "stream",
|
1508 |
"text": [
|
1509 |
-
"/var/folders/fj/ycln97zn6b1ckstg6ksdmgl80000gp/T/
|
1510 |
"\n",
|
1511 |
"\n",
|
1512 |
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
@@ -9861,51 +9861,20 @@
|
|
9861 |
"plt.show()"
|
9862 |
]
|
9863 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9864 |
{
|
9865 |
"cell_type": "code",
|
9866 |
"execution_count": 22,
|
9867 |
"metadata": {},
|
9868 |
-
"outputs": [
|
9869 |
-
{
|
9870 |
-
"ename": "ValueError",
|
9871 |
-
"evalue": "all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 145 and the array at index 1 has size 780",
|
9872 |
-
"output_type": "error",
|
9873 |
-
"traceback": [
|
9874 |
-
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
|
9875 |
-
"\u001b[0;31mValueError\u001b[0m Traceback (most recent call last)",
|
9876 |
-
"Cell \u001b[0;32mIn[22], line 10\u001b[0m\n\u001b[1;32m 7\u001b[0m x \u001b[38;5;241m=\u001b[39m df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcoal_price_data\u001b[39m\u001b[38;5;124m\"\u001b[39m][\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnewcastle\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m 8\u001b[0m y \u001b[38;5;241m=\u001b[39m df[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mM2SL\u001b[39m\u001b[38;5;124m\"\u001b[39m][y_axis]\n\u001b[0;32m---> 10\u001b[0m slope, intercept, r, p, std_err \u001b[38;5;241m=\u001b[39m \u001b[43mstats\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mlinregress\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mslope: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mslope\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mintercept: \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mintercept\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n",
|
9877 |
-
"File \u001b[0;32m/opt/homebrew/anaconda3/envs/py312/lib/python3.12/site-packages/scipy/stats/_stats_mstats_common.py:167\u001b[0m, in \u001b[0;36mlinregress\u001b[0;34m(x, y, alternative)\u001b[0m\n\u001b[1;32m 162\u001b[0m ymean \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39mmean(y, \u001b[38;5;28;01mNone\u001b[39;00m)\n\u001b[1;32m 164\u001b[0m \u001b[38;5;66;03m# Average sums of square differences from the mean\u001b[39;00m\n\u001b[1;32m 165\u001b[0m \u001b[38;5;66;03m# ssxm = mean( (x-mean(x))^2 )\u001b[39;00m\n\u001b[1;32m 166\u001b[0m \u001b[38;5;66;03m# ssxym = mean( (x-mean(x)) * (y-mean(y)) )\u001b[39;00m\n\u001b[0;32m--> 167\u001b[0m ssxm, ssxym, _, ssym \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcov\u001b[49m\u001b[43m(\u001b[49m\u001b[43mx\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mbias\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m1\u001b[39;49m\u001b[43m)\u001b[49m\u001b[38;5;241m.\u001b[39mflat\n\u001b[1;32m 169\u001b[0m \u001b[38;5;66;03m# R-value\u001b[39;00m\n\u001b[1;32m 170\u001b[0m \u001b[38;5;66;03m# r = ssxym / sqrt( ssxm * ssym )\u001b[39;00m\n\u001b[1;32m 171\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ssxm \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0.0\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m ssym \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0.0\u001b[39m:\n\u001b[1;32m 172\u001b[0m \u001b[38;5;66;03m# If the denominator was going to be 0\u001b[39;00m\n",
|
9878 |
-
"File \u001b[0;32m/opt/homebrew/anaconda3/envs/py312/lib/python3.12/site-packages/numpy/lib/function_base.py:2683\u001b[0m, in \u001b[0;36mcov\u001b[0;34m(m, y, rowvar, bias, ddof, fweights, aweights, dtype)\u001b[0m\n\u001b[1;32m 2681\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m rowvar \u001b[38;5;129;01mand\u001b[39;00m y\u001b[38;5;241m.\u001b[39mshape[\u001b[38;5;241m0\u001b[39m] \u001b[38;5;241m!=\u001b[39m \u001b[38;5;241m1\u001b[39m:\n\u001b[1;32m 2682\u001b[0m y \u001b[38;5;241m=\u001b[39m y\u001b[38;5;241m.\u001b[39mT\n\u001b[0;32m-> 2683\u001b[0m X \u001b[38;5;241m=\u001b[39m \u001b[43mnp\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconcatenate\u001b[49m\u001b[43m(\u001b[49m\u001b[43m(\u001b[49m\u001b[43mX\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43my\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43maxis\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;241;43m0\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[1;32m 2685\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ddof \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m:\n\u001b[1;32m 2686\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m bias \u001b[38;5;241m==\u001b[39m \u001b[38;5;241m0\u001b[39m:\n",
|
9879 |
-
"\u001b[0;31mValueError\u001b[0m: all the input array dimensions except for the concatenation axis must match exactly, but along dimension 1, the array at index 0 has size 145 and the array at index 1 has size 780"
|
9880 |
-
]
|
9881 |
-
}
|
9882 |
-
],
|
9883 |
"source": [
|
9884 |
-
"
|
9885 |
-
" return slope * x + intercept\n",
|
9886 |
-
"\n",
|
9887 |
-
"\n",
|
9888 |
-
"y_axis = \"M2SL\"\n",
|
9889 |
-
"\n",
|
9890 |
-
"x = df[\"coal_price_data\"][\"newcastle\"]\n",
|
9891 |
-
"y = df[\"M2SL\"][y_axis]\n",
|
9892 |
-
"\n",
|
9893 |
-
"slope, intercept, r, p, std_err = stats.linregress(x, y)\n",
|
9894 |
-
"\n",
|
9895 |
-
"print(f\"slope: {slope}\")\n",
|
9896 |
-
"print(f\"intercept: {intercept}\")\n",
|
9897 |
-
"print(f\"r: {r}\")\n",
|
9898 |
-
"print(f\"p: {p}\")\n",
|
9899 |
-
"print(f\"std_err: {std_err}\")\n",
|
9900 |
-
"\n",
|
9901 |
-
"\n",
|
9902 |
-
"mymodel = list(map(myfunc, x))\n",
|
9903 |
-
"\n",
|
9904 |
-
"plt.scatter(x, y)\n",
|
9905 |
-
"plt.plot(x, mymodel, color=\"orange\")\n",
|
9906 |
-
"plt.xlabel(\"Newcastle\")\n",
|
9907 |
-
"plt.ylabel(y_axis)\n",
|
9908 |
-
"plt.show()"
|
9909 |
]
|
9910 |
},
|
9911 |
{
|
|
|
1506 |
"name": "stderr",
|
1507 |
"output_type": "stream",
|
1508 |
"text": [
|
1509 |
+
"/var/folders/fj/ycln97zn6b1ckstg6ksdmgl80000gp/T/ipykernel_16548/2627926293.py:1: SettingWithCopyWarning:\n",
|
1510 |
"\n",
|
1511 |
"\n",
|
1512 |
"A value is trying to be set on a copy of a slice from a DataFrame.\n",
|
|
|
9861 |
"plt.show()"
|
9862 |
]
|
9863 |
},
|
9864 |
+
{
|
9865 |
+
"cell_type": "code",
|
9866 |
+
"execution_count": null,
|
9867 |
+
"metadata": {},
|
9868 |
+
"outputs": [],
|
9869 |
+
"source": []
|
9870 |
+
},
|
9871 |
{
|
9872 |
"cell_type": "code",
|
9873 |
"execution_count": 22,
|
9874 |
"metadata": {},
|
9875 |
+
"outputs": [],
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9876 |
"source": [
|
9877 |
+
"y_axis = \"M2SL\""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9878 |
]
|
9879 |
},
|
9880 |
{
|