I've seen a couple of posts on how to make a simple graph that looks something like this:
The code for this would be as follows:
# Create linear regression object
regr = linear_model.LinearRegression()
# Train the model using the training sets
regr.fit(X_train, Y_train)
# Plot outputs
plt.plot(X_test, regr.predict(X_test), color='red',linewidth=3)
I've been working on building a similar thing but using the USA_Housing dataset from Kaggle.
My code is as follows:
# plot the graph
plt.scatter(X_test[0], y_test, color = "black")
plt.plot(X_test[0], y_hat)
plt.xticks(())
plt.yticks(())
plt.show()
Which results in the following:
X_test[0]
is just one of the independent variables (income).
Shouldn't this just make a simple line through the prediction points?
R-squared is around 91 so the fit is good, but I guess I'm confused as to why it would look like this.