Classification in Naive Bayes algorithm

0 votes
Hello everyone. I am trying to create a flood prediction map by using the Naive Bayes algorithm. The types of data which exported raster data is ASCII. I used this data for Random forest algorithm but I don't know how can I implement this data in Naive Bayes algorithm.

Note: When ı used the same technique, I get an error :  AttributeError: 'numpy.ndarray' object has no attribute 'predict'

This is an example which belongs to RF algorithm:

slopedata = numpy.genfromtxt('data_name.txt')
slope = numpy.reshape(slopedata,250*433)
Oct 5 in Machine Learning by Ogun
• 140 points

1 answer to this question.

0 votes


The Numpy module doesn't have a predict attribute. So you need to check your code. If you are facing issues with your code then paste your complete code here.

answered Oct 5 by MD
• 79,930 points
These are my Random forest codes. I used an RF classification for comparing past and future data which was edited from raster data as ASCII data type.  I am trying to make a similar map by using any other algorithm, but i don't know it works or not with the same data type.

train_x = numpy.array([elevation, soil, slope, wetness, annualp]) (past data)

train_x60 = numpy.array([elevation, soil, slope, wetness, annualp60]) (future data)

train_y = floodwatch

clf = ensemble.RandomForestClassifier(n_estimators=100, bootstrap=True, oob_score=True)
clf =, train_y)
print ('OOB score = ', clf.oob_score_)

Ytrain = clf.predict(train_x60)
Ytrain2 = numpy.reshape(Ytrain,[250,433])

To Naive Bayes algorithm

x = numpy.array([elevation, soil, slope, wetness, annualp]).T
y = floodwatch

x_train, x_test, y_train, y_test = train_test_split(x, y,)
GausNB = GaussianNB(), y_train)

y_expect = y_test
y_pred = GausNB.predict(x_test)
print(accuracy_score(y_expect, y_pred))

When I used same future data or different future data ı obtain same map. Because of that, I am not sure the ASCII data proper for these algorithm.


The first thing that you need to check your datatype. So every one step tries to check the datatype. And match that with your requirement.

Related Questions In Machine Learning

0 votes
1 answer

What is greedy approach in Decision tree algorithm?

“Greedy Approach is based on the concept ...READ MORE

answered May 13, 2019 in Machine Learning by Upadhya
0 votes
1 answer
0 votes
1 answer

Example to run KNN algorithm using python

Have a look at this one: from sklearn.datasets ...READ MORE

answered May 8, 2019 in Machine Learning by Harvy
0 votes
1 answer
0 votes
1 answer

Reliability of Bayes Theorem

Baye’s theorem is useful for determining the ...READ MORE

answered Oct 17, 2018 in Data Analytics by kurt_cobain
• 9,320 points
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,564 views
0 votes
3 answers