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, 2020 in Machine Learning by Ogun
• 140 points
974 views

1 answer to this question.

0 votes

Hi@Ogun,

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, 2020 by MD
• 95,440 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 = clf.fit(train_x, train_y)
print ('OOB score = ', clf.oob_score_)

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

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()
GausNB.fit(x_train, y_train)
print(GausNB)

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.

Hi@Ogun,

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
14,222 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

A simple explanation of Naïve Bayes Classification

Naive Bayes Classification uses probability to classify ...READ MORE

answered Feb 22, 2022 in Machine Learning by Nandini
• 5,480 points
259 views
0 votes
1 answer

Naives Bayes Classifier for bag of vectorized sentences

The error is basically the [X_train] which ...READ MORE

answered Apr 11, 2022 in Blockchain by Rahul
• 9,670 points
503 views
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,390 points
599 views
0 votes
2 answers
0 votes
3 answers

What are some best examples of AI applications in our daily life?

Hi Michael, You don’t need to be a ...READ MORE

answered Apr 9, 2020 in Machine Learning by Albert
• 160 points
1,786 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP