I am trying to make a plot that illustrates a point on line created through linear regression. However I run into an err I don’t understand.
Here is my code:
spain_gdp_ppp_capita = country_sub[gdp_ppp_col].loc["Spain"]
spain_gdp_ppp_capita
min_gdp = country_sub['gdp_ppp'].min()
max_gdp = country_sub['gdp_ppp'].max()
min_lat = country_sub['lat'].min()
max_lat = country_sub['lat'].max()
country_sub.plot(kind="scatter", figsize=(10, 6), grid=True,
x=gdp_ppp_col, y=lat_col)
X = np.linspace(min_gdp_ppp, max_gdp_ppp, 1000)
plt.plot(X, t0 +t1 * X, "b")
plt.text(min_gdp_ppp + 22_000, max_lat - 1.0,
fr"$theta_0 = {t0:.2f}$", color = "b")
plt.text(min_gdp_ppp + 22_000, max_lat - 3.0,
fr"$theta_1 = {t1 * 1e5:.2f} times 10^{{-5}}$", color="b")
plt.plot([spain_gdp_ppp_capita],
[min_lat, spain_predicted_lat], "r--")
plt.text(spain_gdp_ppp_capita + 1000, 5.0,
fr"Prediction = {spain_predicted_lat:.2f}", color="r")
plt.text(spain_gdp_per_capita, spain_predicted_lat, "ro")
plt.axis([min_gdp, max_gdp, min_life_sat, max_life_sat])
plt.show()
I end up with the following error code:
ValueError: x and y must have same first dimension, but have shapes (1,) and (2,)
And a graph that looks like this:
I was expecting a graph that looked more like this: