I am trying to do multiple linear regression. I splited the data and put into training model. But i have a problem when i am trying to visualize results.
x = data.iloc[:,:-2].values # independent
y = data.iloc[:,-1].values # dependent profit
print(y)
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size = 1/3, random_state = 0)
regressor = LinearRegression()
regressor.fit(x_train, y_train)
y_pred = regressor.predict(x_test)
x_pred = regressor.predict(x_train)
plt.scatter(x_train, y_train, color = "green")
plt.plot(x_train, x_pred, color = "red")
plt.title("Companies Profit Prediction")
plt.xlabel("Independent Variables")
plt.ylabel("Profit")
plt.show()
I have companies.csv which have columns rdspend, administration, marketing spend and profit. So my dependent variable is profit and independent variables are others(rdspend, admi...). I get the ValueError for plt.scatter saying x,y must be same size. x_train is multidimensional array while y_train is normal array. I want to see training set results. Somehow i need to change either x_train or y_train i guess. How can i solve that?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…