
import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn import model_selection
import time  

def naive_Bayes(X, y):

	results = []
	times = []
	accuracy_diff = []

	for x in range(0,200):

		# Dividing the dataset into Training Set and Test Set
		X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state = int(time.time()))

		start = time.time()

		# Applying Naive Bayes 
		gnb = GaussianNB()
		gnb.fit(X_train, y_train)


		# Predicting the results
		y_pred = gnb.predict(X_test)


		# Checking the accuracy on the test set
		result = gnb.score(X_test, y_test)		


		# Checking the integrity of the model using 10-fold cross validation
		kfold = model_selection.KFold(n_splits = 10, random_state = int(time.time()))
		modelCV = GaussianNB()
		scoring = 'accuracy'
		result_cv = model_selection.cross_val_score(modelCV, X_train, y_train, cv = kfold, scoring = scoring)
		result_cv = np.mean(result_cv)


		# Calculating the difference between model prediction and CV result
		aux_accuracy_diff = result - result_cv
		if aux_accuracy_diff < 0:
			aux_accuracy_diff = -aux_accuracy_diff


		# Calculating elapsed time
		end = time.time()
		elapsed_time = end - start

		
		results.append(result.mean())
		times.append(elapsed_time)
		accuracy_diff.append(aux_accuracy_diff)


	# Returning the average performance of the Algorithm
	return[np.mean(results), np.var(results), np.mean(times), np.mean(accuracy_diff)]













ebd995cbd4f4e77bbc3ad5c86cff4fe66cee969b
<mask token>

<mask token>


def naive_Bayes(X, y):
    results = []
    times = []
    accuracy_diff = []
    for x in range(0, 200):
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size
            =0.3, random_state=int(time.time()))
        start = time.time()
        gnb = GaussianNB()
        gnb.fit(X_train, y_train)
        y_pred = gnb.predict(X_test)
        result = gnb.score(X_test, y_test)
        kfold = model_selection.KFold(n_splits=10, random_state=int(time.
            time()))
        modelCV = GaussianNB()
        scoring = 'accuracy'
        result_cv = model_selection.cross_val_score(modelCV, X_train,
            y_train, cv=kfold, scoring=scoring)
        result_cv = np.mean(result_cv)
        aux_accuracy_diff = result - result_cv
        if aux_accuracy_diff < 0:
            aux_accuracy_diff = -aux_accuracy_diff
        end = time.time()
        elapsed_time = end - start
        results.append(result.mean())
        times.append(elapsed_time)
        accuracy_diff.append(aux_accuracy_diff)
    return [np.mean(results), np.var(results), np.mean(times), np.mean(
        accuracy_diff)]

import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn import model_selection
import time


def naive_Bayes(X, y):
    results = []
    times = []
    accuracy_diff = []
    for x in range(0, 200):
        X_train, X_test, y_train, y_test = train_test_split(X, y, test_size
            =0.3, random_state=int(time.time()))
        start = time.time()
        gnb = GaussianNB()
        gnb.fit(X_train, y_train)
        y_pred = gnb.predict(X_test)
        result = gnb.score(X_test, y_test)
        kfold = model_selection.KFold(n_splits=10, random_state=int(time.
            time()))
        modelCV = GaussianNB()
        scoring = 'accuracy'
        result_cv = model_selection.cross_val_score(modelCV, X_train,
            y_train, cv=kfold, scoring=scoring)
        result_cv = np.mean(result_cv)
        aux_accuracy_diff = result - result_cv
        if aux_accuracy_diff < 0:
            aux_accuracy_diff = -aux_accuracy_diff
        end = time.time()
        elapsed_time = end - start
        results.append(result.mean())
        times.append(elapsed_time)
        accuracy_diff.append(aux_accuracy_diff)
    return [np.mean(results), np.var(results), np.mean(times), np.mean(
        accuracy_diff)]


import numpy as np
from sklearn.naive_bayes import GaussianNB
from sklearn.model_selection import train_test_split, cross_val_score
from sklearn import model_selection
import time  

def naive_Bayes(X, y):

	results = []
	times = []
	accuracy_diff = []

	for x in range(0,200):

		# Dividing the dataset into Training Set and Test Set
		X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state = int(time.time()))

		start = time.time()

		# Applying Naive Bayes 
		gnb = GaussianNB()
		gnb.fit(X_train, y_train)


		# Predicting the results
		y_pred = gnb.predict(X_test)


		# Checking the accuracy on the test set
		result = gnb.score(X_test, y_test)		


		# Checking the integrity of the model using 10-fold cross validation
		kfold = model_selection.KFold(n_splits = 10, random_state = int(time.time()))
		modelCV = GaussianNB()
		scoring = 'accuracy'
		result_cv = model_selection.cross_val_score(modelCV, X_train, y_train, cv = kfold, scoring = scoring)
		result_cv = np.mean(result_cv)


		# Calculating the difference between model prediction and CV result
		aux_accuracy_diff = result - result_cv
		if aux_accuracy_diff < 0:
			aux_accuracy_diff = -aux_accuracy_diff


		# Calculating elapsed time
		end = time.time()
		elapsed_time = end - start

		
		results.append(result.mean())
		times.append(elapsed_time)
		accuracy_diff.append(aux_accuracy_diff)


	# Returning the average performance of the Algorithm
	return[np.mean(results), np.var(results), np.mean(times), np.mean(accuracy_diff)]












