



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




marks) Write a program in Python to implement the decision tree algorithm. You should read a comma delimited dataset (csv file), and output to the screen your decision tree and the training set accuracy in some readable format. Here are csv dataset of given table : #of reported covid19 cases temperature humid Followed sopfollowe d followed
LOW cool high weak no LOW hot high strong yes AVERAGE cool high weak no HIGH mild high weak no HIGH hot normal weak no HIGH hot normal strong no AVERAGE hot normal strong yes LOW mild high weak no LOW hot normal weak yes HIGH mild normal weak no LOW mild normal strong yes AVERAGE mild high strong yes AVERAGE hot normal weak no HIGH mild high strong no
FINAL TERMEXAMINATION – SPRINGSEMESTER – 2020 (COURSE TITLE Artificial Intelligence LabCOURSE CODECSL-411) Class: BS (CS)-6 (Morning / Evening) Course Instructor: Irfan Mustafa Last Date to submit: 26-6-2020 (12:00 pm) Max Marks: 15 Student’s Name: Muhammad Jawwad Enrollment No:02-134172- Note: create a folder on your desktop of your name and enrollment (abc-001).Then Create a word(.doc) file in the folder. The name of the file is in same pattern you create a folder ( your name and enrollment) and store all output and code screen shot in the file. Add complete coding of your program (android project folder) in main folder, and create a .zip file of main folder and send email .zip file to ([email protected]) with the subject of your name and enrollment (abc-001- AI(sec-“A/C”)MID20 ), And submit word(.doc) file on LMS before due date. In order to avoid any run time electricity and internet unavailability situation, it is suggested that keep yourlaptop charged. Also activate 3G/4G connection as an alternative of Wifi/internet option to upload your solution. covid19.csv
For output, you can choose how to draw the tree so long as it is clear what the tree is. For example: #of reported covid19 cases = LOW | humid = high: no | humid = normal: yes #of reported covid19 cases = HIGH: NO #of reported covid19 cases = AVERAGE | Followed sopfollowed followed = weak: no | Followed sopfollowed followed = strong: yes #of reported covid19 cases HIGH NO LOW TEMPRATURE COOL NO MILD HUMIDITY NORMAL YES HIGH NO HOT YES AVERAGE SOPs FOLLOWED STRONG YES WEAK NO
print ("Dataset Length: ", len(balance_data)) print ("Dataset Shape: ", balance_data.shape)
print ("Dataset: ",balance_data.head()) return balance_data
def splitdataset(balance_data):
X = balance_data.values[:, 1:5] Y = balance_data.values[:, 0]
X_train, X_test, y_train, y_test = train_test_split( X, Y, test_size = 0.3, random_state = 100) return X, Y, X_train, X_test, y_train, y_test
def train_using_gini(X_train, X_test, y_train):
clf_gini = DecisionTreeClassifier(criterion = "gini", random_state = 100,max_depth=3, min_samples_leaf=5)
clf_gini.fit(X_train, y_train) return clf_gini
def tarin_using_entropy(X_train, X_test, y_train):
clf_entropy = DecisionTreeClassifier( criterion = "entropy", random_state = 100, max_depth = 3, min_samples_leaf = 5)
clf_entropy.fit(X_train, y_train) return clf_entropy
def prediction(X_test, clf_object):
y_pred = clf_object.predict(X_test) print("Predicted values:") print(y_pred) return y_pred
def cal_accuracy(y_test, y_pred): print("Confusion Matrix: ", confusion_matrix(y_test, y_pred)) print ("Accuracy : ", accuracy_score(y_test,y_pred)*100) print("Report : ", classification_report(y_test, y_pred))