matplotlib.pyplot.plot() doesn't show the graph
<p>I am learning Python and I have a side project to learn to display data using matplotlib.pyplot module.  Here is an example to display the data using dates[] and prices[] as data.  Does anyone know why we need line 5 and line 6?  I am confused why this step is needed to have the graph displayed.   </p>

<pre><code>from sklearn import linear_model
import matplotlib.pyplot as plt

def showgraph(dates, prices):
  dates  = numpy.reshape(dates, (len(dates), 1))   # line 5
  prices = numpy.reshape(prices, (len(prices), 1)) # line 6

  linear_mod = linear_model.LinearRegression()
  linear_mod.fit(dates,prices)
  plt.scatter(dates,prices,color='yellow') 
  plt.plot(dates,linear_mod.predict(dates),color='green')
  plt.show()
</code></pre>

<p>Line 5 and 6 transform what Im assuming are row vectors (im not sure how <code>data</code> and <code>prices</code> are encoded before this transformation) into column  vectors. So now you have vectors that look like this. </p>

<pre><code>[0,
 1, 
 2, 
 3]
</code></pre>

<p>which is the form that <code>linear_model.Linear_Regression.fit()</code> is expecting. The reshaping was not necessary for plotting under the assumption that data and prices are row vectors.</p>

python matplotlib linear-regression