naive_bayes (1).py - # -*- coding: utf-8...

This preview shows page 1 - 2 out of 2 pages.

# -*- coding: utf-8 -*-"""Naive_Bayes.ipynbAutomatically generated by Colaboratory.Original file is located at"""import numpy as npimport pandas as pdimport scipy.iosample_data = scipy.io.loadmat("/content/sample_data/fashion_mnist.mat")#Training DataframeAverage_tr = []StdDev_tr = []for i in range(12000):Average_tr.append(sample_data["trX"][i].mean())StdDev_tr.append(sample_data["trX"][i].std())X_train = pd.DataFrame(list(zip(Average_tr,StdDev_tr,sample_data["trY"][0])),columns=["X1","X2","Y"])Y_train = pd.DataFrame(sample_data["trY"][0],columns=["Y"])Average_ts = []StdDev_ts = []for i in range(2000):Average_ts.append(sample_data["tsX"][i].mean())StdDev_ts.append(sample_data["tsX"][i].std())X_test = pd.DataFrame(list(zip(Average_ts,StdDev_ts)),columns=["X1","X2"])Y_test = pd.DataFrame(sample_data["tsY"][0],columns=["Y"])Y_test = np.array(Y_test)class NaiveBayes():def fit(self,X,Y):self.samples, self.features = X.shapeself.classes = np.unique(Y)self.n_class = len(self.classes)self.mean = np.zeros((self.n_class,self.features-1))
End of preview. Want to read all 2 pages?

Upload your study docs or become a

Course Hero member to access this document

Term
Spring
Professor
Jingrui He
Tags
training, Posteriors

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture