https://www.kaggle.com/paree24/development-index i am trying to plot my linear regression model but i just cant seem to make in work.
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from sklearn.linear_model import LinearRegression
from sklearn.model_selection import train_test_split
from scipy.stats import shapiro
from sklearn.metrics import mean_squared_error
from sklearn.preprocessing import normalize
from math import sqrt
from sklearn.model_selection import cross_val_score
dataset = pd.read_csv("Development.csv")
x = np.array(dataset.drop(columns= ["Area (sq. mi.)", "Pop. Density ", "Development Index", "Infant mortality "]))
y = np.array(dataset["Infant mortality "])
plot1 = dataset.plot(x= "GDP ($ per capita)", y='Infant mortality ', style='o')
plot2 = dataset.plot(x= "Literacy (%)", y='Infant mortality ', style='o')
plot3 = dataset.plot(x= "Population", y='Infant mortality ', style='o')
plt.tight_layout()
plt.show()
stat, p = shapiro(y)
print(f"показатель {p}")
print(f"статистика {stat}")
#разделение модели для модели
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.25, random_state=10)
regressor = LinearRegression()
regressor.fit(x_train, y_train)
print(f"regressor.intercept_ {regressor.intercept_}")
print(f"regressor.coef_{regressor.coef_}")
scores = cross_val_score(regressor, x, y, cv=5)
print(scores)
print("%0.2f accuracy with a standard deviation of %0.2f" % (scores.mean(), scores.std()))
y_pred = regressor.predict(x_test)
df = pd.DataFrame({'Actual': y_test.flatten(), 'Predicted': y_pred.flatten()})
and this is the plot i am trying to make in 3d
plt.scatter(x_test[0:,1], y_test)
plt.plot(x_test, y_pred, color='orange', linewidth=1 )
plt.show()
and this is what it shows
I have wasted 6 hours on this and i still cant figure out how to plot this, this is the closest i could come
plt3d = plt.figure().gca(projection='3d')
plt3d.view_init(azim=135)
plt3d.plot_trisurf(x_test[0:,1], y_pred[0:,1], alpha=0.7, antialiased=True)
and it gives me an error: IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed
any ideas?