Friday, May 25, 2018

Classification using NaiveBayse Algorithm using Python

#Import Library of Gaussian Naive Bayes model
from sklearn.naive_bayes import GaussianNB
import numpy as np
import pandas as pd
 
#assigning predictor and target variables
dataF = pd.DataFrame()
dataF["x1"] = np.random.random_sample((5,)) + 1
dataF["x2"] = np.random.random_sample((5,)) + 2 

dataL = pd.DataFrame()
dataL = np.array([3, 3, 4, 3, 4])
 
#Create a Gaussian Classifier
model = GaussianNB()

# Train the model using the training sets 
model.fit(dataF, dataL)

#Predict Output 
predicted= model.predict([[1,2],[3,4]])
print(predicted)

Output: ([3,4])
 
-Thank you 

No comments:

Post a Comment