Skip to main content

Posts

Showing posts from October, 2023

Exp 11

11. Write a program for Naive Bayesian Classification in Python import pandas as pd import numpy as np from sklearn import datasets iris = datasets.load_iris() # importing the dataset iris.data # showing the iris data X=iris.data #assign the data to the X y=iris.target #assign the target/flower type to the y print (X.shape) print (y.shape) fromsklearn.model_selection import train_test_split X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=9) fromsklearn.naive_bayes import GaussianNB nv = GaussianNB() # create a classifier nv.fit(X_train,y_train) # fitting the data fromsklearn.metrics import accuracy_score y_pred = nv.predict(X_test) # store the prediction data accuracy_score(y_test,y_pred) # calculate the accuracy

Exp 10

  10. Write a program to calculate chi-square value using Python. Report your observation. import math a=[[ 250,200],    [50,1000]] print("Elements in dataset a are:\n"); for i in a:     for j in i:         print(j,end = " ")     print() row1tot= a[0][0]+a[0][1]; row2tot=a[1][0]+a[1][1]; col1tot=a[0][0]+a[1][0]; col2tot=a[0][1]+a[1][1]; print("\nRow one total:",row1tot);  print("\nRow two total:",row2tot)  print("\nColumn one total:",col1tot);  print("\n Column two total:",col2tot);  totalValueallcolumns= col1tot+col2tot; totalValueallrows= row1tot+row2tot; print("\nTotal value of all columns:",totalValueallcolumns);  print("\nTotal value of all rows:",totalValueallrows);  e00= (col1tot*row1tot)/totalValueallcolumns; e01= (col2tot*row1tot)/totalValueallcolumns; e10= (col1tot*row2tot)/totalValueallcolumns; e11= (col2tot*row2tot)/totalValueallcolumns; print("\n...

Exp 16

 Visualize the datasets using matplotlib in python.(Histogram, Bar chart, Pie chart etc.,) Histogram import matplotlib.pyplot as plt x = [1,1,2,3,3,5,7,8,9,10, 10,11,11,13,13,15,16,17,18,18, 18,19,20,21,21,23,24,24,25,25, 25,25,26,26,26,27,27,27,27,27, 29,30,30,31,33,34,34,34,35,36, 36,37,37,38,38,39,40,41,41,42, 43,44,45,45,46,47,48,48,49,50, 51,52,53,54,55,55,56,57,58,60, 61,63,64,65,66,68,70,71,72,74, 75,77,81,83,84,87,89,90,90,91 ] plt.style.use('ggplot') plt.hist(x, bins=10) plt.show() output: //// Bar Chart: import matplotlib.pyplot as plt country = ['A', 'B', 'C', 'D', 'E'] gdp_per_capita = [45000, 42000, 52000, 49000, 47000] plt.bar(country, gdp_per_capita) plt.title('Country Vs GDP Per Capita') plt.xlabel('Country') plt.ylabel('GDP Per Capita') plt.show() output:///// Pie chart: # Import libraries from matplotlib import pyplot as plt import numpy as np # Creating dataset cars = ['AUDI', 'BMW...