Advertisement
BotByte

Untitled

Sep 17th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.40 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. @author: Rafsan Mazumder
  4.  
  5. @project: Decision Tree 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.tree import DecisionTreeClassifier # Import Decision Tree Classifier
  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. from sklearn.model_selection import validation_curve
  20. from sklearn.datasets import load_iris
  21. from sklearn.linear_model import Ridge
  22.  
  23. datasets = pd.read_csv("C:/Users/BOT/Desktop/Machine Learning/Rainfall Prediction/testMonthly.csv")
  24.  
  25. label = datasets.loc[:, "Rainfall"]
  26. features = datasets.loc[:, :"Month"]
  27.  
  28. numpy_label = label.as_matrix()
  29. numpy_features = features.as_matrix()
  30.  
  31. sizeRow = 16755
  32.  
  33. blockSize = 700
  34.  
  35. for index in range(0, sizeRow):
  36.   numpy_label[index] = numpy_label[index] / blockSize
  37.  
  38. X = numpy_features
  39. y = numpy_label
  40.  
  41. X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
  42.  
  43. # Create Decision Tree classifer object
  44. clf = DecisionTreeClassifier()
  45.  
  46. # Train Decision Tree Classifer
  47. clf = clf.fit(X_train,y_train)
  48.  
  49. #Predict the response for test dataset
  50. y_pred = clf.predict(X_test)
  51.  
  52. print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement