Q:

Why is prediction not plotted?

Here is my code in Python 3:
from sklearn import linear_model
import numpy as np
obj = linear_model.LinearRegression()
allc = np.array([[0,0],[1,1],[2,2],[3,3],[4,4],[5,5],[6,6]])
X=allc[:,0]
X=X.reshape(-1, 1)
Y=X.reshape(X.shape[0],-1)
obj.fit(X, Y)
print(obj.predict(7))
import matplotlib.pyplot as plt
plt.scatter(X,Y,color='black')
plt.plot(X[0],obj.predict(7),color='black',linewidth=3)
plt.show()

My plotted data looks this way:

After fitting, obj.predict(7) equals [7.]
What am I doing wrong? I expected to see 7.7 point being plotted.

A:

The plot method is taking an array for the X-axis and an array for the Y-axis, and draws a line according to those arrays. You tried to draw a point using a method for lines...
For your code to work (I have tested it and it worked) switch this line:
plt.plot(X[0],obj.predict(7),color='black',linewidth=3)

with this line: 
plt.scatter(7,obj.predict(7),color='black',linewidth=3)

The scatter method will take the point given (7, 7) and put it in the graph just like you wanted.
I hope this helped :)

