Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- @author: Rafsan Mazumder
- @project: Decision Tree Classifier for Monthly Model
- """
- import numpy as np
- import matplotlib.pyplot as plt
- import pandas as pd
- from IPython.display import display
- import sklearn
- from sklearn.tree import DecisionTreeClassifier # Import Decision Tree Classifier
- from sklearn.model_selection import train_test_split # Import train_test_split function
- from sklearn import metrics #Import scikit-learn metrics module for accuracy calculation
- from sklearn.model_selection import validation_curve
- from sklearn.datasets import load_iris
- from sklearn.linear_model import Ridge
- datasets = pd.read_csv("C:/Users/BOT/Desktop/Machine Learning/Rainfall Prediction/testMonthly.csv")
- label = datasets.loc[:, "Rainfall"]
- features = datasets.loc[:, :"Month"]
- numpy_label = label.as_matrix()
- numpy_features = features.as_matrix()
- sizeRow = 16755
- blockSize = 700
- for index in range(0, sizeRow):
- numpy_label[index] = numpy_label[index] / blockSize
- X = numpy_features
- y = numpy_label
- X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=1)
- # Create Decision Tree classifer object
- clf = DecisionTreeClassifier()
- # Train Decision Tree Classifer
- clf = clf.fit(X_train,y_train)
- #Predict the response for test dataset
- y_pred = clf.predict(X_test)
- print("Accuracy:",metrics.accuracy_score(y_test, y_pred))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement