############################ ## Rohini Pandhi ## ## Homework Assignment 2 ## ## Run File ## ## 01/23/2014 ## ############################ import argparse from hw2 import load_iris_data, cross_validate, knn, nb, lr # Load Iris dataset (features, species, species_names) = load_iris_data() # Argument parse parser = argparse.ArgumentParser(description='Select KNN, Naive Bayes, or Logistic Regression') parser.add_argument('-c', '--classifier', help='a classifier type: KNN, NB, or LR (if none selected, default will run all', required=False) args = parser.parse_args() try: if (args.classifier.upper() == "KNN"): classifier_list = [("KNN",knn)] elif (args.classifier.upper() == "NB"): classifier_list = [("Naive Bayes",nb)] elif (args.classifier.upper() == "LR"): classifier_list = [("Logistic Regression",lr)] except: classifier_list = [("KNN",knn), ("Naive Bayes",nb), ("Logistic Regression",lr)] #using imported functions above # Loop through each tuple of the classifier list for (classifier_string, classifier_function) in classifier_list:
from hw2 import load_iris_data, cross_validate, knn, nb, lr, logistic (XX,yy,y)=load_iris_data() classfiers_to_cv=[("kNN",knn),("Naive Bayes",nb), ("Linear Regression",lr), ("Logistic REgression",logistic)] for (c_label, classifer) in classfiers_to_cv : print print "---> %s <---" % c_label best_k=0 best_cv_a=0 for k_f in [2,3,5,10,15,30,50,75] : cv_a = cross_validate(XX, yy, classifer, k_fold=k_f) if cv_a > best_cv_a : best_cv_a=cv_a best_k=k_f print "fold <<%s>> :: acc <<%s>>" % (k_f, cv_a) print "\n %s Highest Accuracy: fold <<%s>> :: <<%s>>\n" % (c_label, best_k, best_cv_a)
############################ ## Rohini Pandhi ## ## Homework Assignment 2 ## ## Run File ## ## 01/23/2014 ## ############################ import argparse from hw2 import load_iris_data, cross_validate, knn, nb, lr # Load Iris dataset (features, species, species_names) = load_iris_data() # Argument parse parser = argparse.ArgumentParser( description='Select KNN, Naive Bayes, or Logistic Regression') parser.add_argument( '-c', '--classifier', help= 'a classifier type: KNN, NB, or LR (if none selected, default will run all', required=False) args = parser.parse_args() try: if (args.classifier.upper() == "KNN"): classifier_list = [("KNN", knn)] elif (args.classifier.upper() == "NB"): classifier_list = [("Naive Bayes", nb)] elif (args.classifier.upper() == "LR"): classifier_list = [("Logistic Regression", lr)]