title: pyspark : NameError: name 'spark' is not defined
body: <p>I am copying the pyspark.ml example from the official document website:
  <a href="http://spark.apache.org/docs/latest/api/python/pyspark.ml.html#pyspark.ml.Transformer" rel="noreferrer">http://spark.apache.org/docs/latest/api/python/pyspark.ml.html#pyspark.ml.Transformer</a></p>
  
  <pre><code>data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),(Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]
  df = spark.createDataFrame(data, ["features"])
  kmeans = KMeans(k=2, seed=1)
  model = kmeans.fit(df)
  </code></pre>
  
  <p>However, the example above wouldn't run and gave me the following errors:</p>
  
  <pre><code>---------------------------------------------------------------------------
  NameError                                 Traceback (most recent call last)
  &lt;ipython-input-28-aaffcd1239c9&gt; in &lt;module&gt;()
        1 from pyspark import *
        2 data = [(Vectors.dense([0.0, 0.0]),), (Vectors.dense([1.0, 1.0]),),(Vectors.dense([9.0, 8.0]),), (Vectors.dense([8.0, 9.0]),)]
  ----&gt; 3 df = spark.createDataFrame(data, ["features"])
        4 kmeans = KMeans(k=2, seed=1)
        5 model = kmeans.fit(df)
  
  NameError: name 'spark' is not defined
  </code></pre>
  
  <p>What additional configuration/variable needs to be set to get the example running?</p>