You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@spark.apache.org by Rahul Bhojwani <ra...@gmail.com> on 2014/07/09 11:24:59 UTC

Error using MLlib-NaiveBayes : "Matrices are not aligned"

I am using Naive Bayes in MLlib .
Below I have printed log of *model.theta*. after training on train data.
You can check that it contains 9 features for 2 class classification.

>>print numpy.log(model.theta)

[[ 0.31618962  0.16636852  0.07200358  0.05411449  0.08542039  0.17620751
   0.03711986  0.07110912  0.02146691]
 [ 0.26598639  0.23809524  0.06258503  0.01904762  0.05714286  0.18231293
   0.08911565  0.03061224  0.05510204]]




 I am giving the same no. of features for prediction but I am getting
error: *matrices not alligned.*

*ERROR:*

Traceback (most recent call last):
  File ".\naive_bayes_analyser.py", line 192, in <module>
    prediction =
model.predict(array([float(pos_count),float(neg_count),float(need_count),float(goal_count),float(try_co
unt),float(means_count),float(persist_count),float(complete_count),float(fail_count)]))
  File "F:\spark-0.9.1\spark-0.9.1\python\pyspark\mllib\classification.py",
line 101, in predict
    return numpy.argmax(self.pi + dot(x, self.theta))
ValueError: matrices are not aligned



Can someone suggest me the possible error/mistake?
Thanks in advance
-- 
Rahul K Bhojwani
3rd Year B.Tech
Computer Science and Engineering
National Institute of Technology, Karnataka