In [1]:
from pyspark import SparkContext 
sc = SparkContext('local','example')

In [3]:
exec(open('doweathclass_gendata.py').read())

In [5]:
datax_rdd


Out[5]:
PythonRDD[7] at RDD at PythonRDD.scala:43

In [6]:
datax_rdd.take(3)


Out[6]:
[LabeledPoint(0.0, [1.0,0.0,0.0,85.0,85.0,0.0]),
 LabeledPoint(0.0, [1.0,0.0,0.0,80.0,90.0,1.0]),
 LabeledPoint(1.0, [0.0,1.0,0.0,83.0,86.0,0.0])]

In [9]:
exec(open('doweathclass_naivebayes.py').read())


<pyspark.mllib.classification.NaiveBayesModel object at 0x7f972803cc88>
[1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0]
Naive Bayes: Conf.Mat. and Per Corr
[[ 3.  2.]
 [ 0.  9.]]
0.857142857143
/home/vahid/anaconda3/envs/py34/lib/python3.4/site-packages/ipykernel/__main__.py:34: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

In [10]:
exec(open('doweathclass_dectree.py').read())


DecisionTreeModel classifier of depth 3 with 9 nodes
  If (feature 1 <= 0.0)
   If (feature 4 <= 80.0)
    If (feature 3 <= 68.0)
     Predict: 0.0
    Else (feature 3 > 68.0)
     Predict: 1.0
   Else (feature 4 > 80.0)
    If (feature 0 <= 0.0)
     Predict: 0.0
    Else (feature 0 > 0.0)
     Predict: 0.0
  Else (feature 1 > 0.0)
   Predict: 1.0

Decision Tree: Conf.Mat. and Per Corr
[[ 5.  0.]
 [ 2.  7.]]
0.857142857143
/home/vahid/anaconda3/envs/py34/lib/python3.4/site-packages/ipykernel/__main__.py:38: DeprecationWarning: using a non-integer number instead of an integer will result in an error in the future

In [11]:
newpoint  = np.array([1,0,0,68,79,0])
my_nbmodel.predict(newpoint)


Out[11]:
1.0

In [14]:
dt_model.predict(newpoint)


Out[14]:
0.0

In [16]:
print(dt_model.toDebugString())


DecisionTreeModel classifier of depth 3 with 9 nodes
  If (feature 1 <= 0.0)
   If (feature 4 <= 80.0)
    If (feature 3 <= 68.0)
     Predict: 0.0
    Else (feature 3 > 68.0)
     Predict: 1.0
   Else (feature 4 > 80.0)
    If (feature 0 <= 0.0)
     Predict: 0.0
    Else (feature 0 > 0.0)
     Predict: 0.0
  Else (feature 1 > 0.0)
   Predict: 1.0


In [ ]: