Git Product home page Git Product logo

bayes-classifier's Introduction

Bayes-Classifier

Aim:

To Construct a Bayes Classifier to classiy iris dataset using Python.

Algorithm:

Input:

  • X: the training data, where each row represents a sample and each column represents a feature.
  • y: the target labels for the training data.
  • X_test: the testing data, where each row represents a sample and each column represents a feature.

Output:

  • y_pred: the predicted labels for the testing data.
  1. Create a BayesClassifier class with the following methods: a. init method to initialize the Gaussian Naive Bayes classifier from scikit-learn. b. fit method to fit the classifier to the training data using the Gaussian Naive Bayes algorithm from scikit-learn. c. predict method to make predictions on the testing data using the fitted classifier from scikit-learn.
  2. Load the Iris dataset using the load_iris function from scikit-learn.
  3. Split the data into training and testing sets using the train_test_split function from scikit-learn.
  4. Create a BayesClassifier instance.
  5. Train the classifier on the training data using the fit method.
  6. Make predictions on the testing data using the predict method.
  7. Evaluate the classifier's accuracy using the accuracy_score function from scikit-learn.

Program:

Developed by: Gunaseelan G
Reg no: 212221230031
import numpy as np
from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.naive_bayes import GaussianNB
from sklearn.metrics import accuracy_score
class BayesClassifier:
  def __init__(self):
    self.clf=GaussianNB()
  def fit(self,X,y):
    self.clf.fit(X,y)
  def predict(self,X):
    return self.clf.predict(X)
iris=load_iris()
X_train,X_test,y_train,y_test=train_test_split(iris.data,iris.target,test_size=0.3,random_state=38)
clf=BayesClassifier()
clf.fit(X_train,y_train)
y_pred=clf.predict(X_test)
accuracy=accuracy_score(y_test,y_pred)
print("Accuracy:",accuracy)

Output:

i-1

Result:

Hence, Bayes classifier for iris dataset is implemented successfully

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.