BotByte

Untitled

Sep 17th, 2019
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.11 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: Rafsan Mazumder
  4.  
  5. @project: Naive Bayes Classifier for Monthly Model
  6.  
  7. """
  8.  
  9. import numpy as np
  10. import matplotlib.pyplot as plt
  11. import pandas as pd
  12. from IPython.display import display
  13. import sklearn
  14.  
  15. from sklearn.naive_bayes import GaussianNB
  16. from sklearn.model_selection import train_test_split # Import train_test_split function
  17. from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
  18.  
  19. datasets = pd.read_csv("C:/Users/BOT/Desktop/Machine Learning/Rainfall Prediction/testMonthly.csv")
  20.  
  21. label = datasets.loc[:, "Rainfall"]
  22. features = datasets.loc[:, :"Month"]
  23.  
  24. numpy_label = label.as_matrix()
  25. numpy_features = features.as_matrix()
  26.  
  27. sizeRow = 16755
  28.  
  29. blockSize = 700
  30.  
  31. for index in range(0, sizeRow):
  32.   numpy_label[index] = numpy_label[index] / blockSize
  33.  
  34.  
  35. X = numpy_features
  36. y = numpy_label
  37.  
  38. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
  39.  
  40. gnb = GaussianNB()
  41. gnb.fit(X_train, y_train)
  42.  
  43. y_pred = gnb.predict(X_test)
  44.  
  45. print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
Advertisement
Add Comment
Please, Sign In to add comment