Пример #1
0
try: 
  if (args.classifier.upper() == "KNN"): 
    classifier_list = [("KNN",knn)]
  elif (args.classifier.upper() == "NB"):
    classifier_list = [("Naive Bayes",nb)]
except:
  classifier_list = [("KNN",knn), ("Naive Bayes",nb)] #using imported functions above

# Loop through each tuple of the classifier list
for (classifier_string, classifier_function) in classifier_list:
  
  print "\n-------- %s --------" % classifier_string

  best_kfolds = 0
  best_cv = 0

  # Define specific set of folds that split the dataset in an even way
  for kfolds in [2,3,5,10,15,30,50,75,150]: 

    cv = cross_validate(features, species, classifier_function, kfolds)

    if cv > best_cv:
      best_cv = cv
      best_kfolds = kfolds
    
    # For each fold, print out it's accuracy in the cross validation function
    print "Fold <<%s>> :: Accuracy <<%s>>" % (kfolds, cv)

  # At the end, print the highest accuracy fold
  print "Highest Accuracy: <<%s>> :: Fold <<%s>>\n" % (best_cv, best_kfolds)  
Пример #2
0
from hw1 import load_iris_data, cross_validate, knn, nb
# Imports functions and opject definitions from hw1.py

(iris_petal_measurements, iris_classes, iris_classnames) = load_iris_data()

classfiers_to_cv = [("kNN", knn), ("Naive Bayes", nb)]

for (c_label, classifer) in classfiers_to_cv:

    print
    print "---> %s <---" % c_label

    best_k = 0
    best_cv_a = 0
    foldsizes = [2, 3, 5, 10, 15, 30, 50, 75, 150]
    #These fold sizes are evenly divisible into the dataset intentionally

    for k_f in foldsizes:
        cv_a = cross_validate(iris_petal_measurements,
                              iris_classes,
                              classifer,
                              k_fold=k_f)
        if cv_a > best_cv_a:
            best_cv_a = cv_a
            best_k = k_f

        print "foldsize <<%s>> :: test accuracy <<%s>>" % (k_f, cv_a)

    print "Highest Accuracy: fold <<%s>> :: <<%s>>" % (best_k, best_cv_a)
Пример #3
0
    if (args.classifier.upper() == "KNN"):
        classifier_list = [("KNN", knn)]
    elif (args.classifier.upper() == "NB"):
        classifier_list = [("Naive Bayes", nb)]
except:
    classifier_list = [("KNN", knn),
                       ("Naive Bayes", nb)]  #using imported functions above

# Loop through each tuple of the classifier list
for (classifier_string, classifier_function) in classifier_list:

    print "\n-------- %s --------" % classifier_string

    best_kfolds = 0
    best_cv = 0

    # Define specific set of folds that split the dataset in an even way
    for kfolds in [2, 3, 5, 10, 15, 30, 50, 75, 150]:

        cv = cross_validate(features, species, classifier_function, kfolds)

        if cv > best_cv:
            best_cv = cv
            best_kfolds = kfolds

        # For each fold, print out it's accuracy in the cross validation function
        print "Fold <<%s>> :: Accuracy <<%s>>" % (kfolds, cv)

    # At the end, print the highest accuracy fold
    print "Highest Accuracy: <<%s>> :: Fold <<%s>>\n" % (best_cv, best_kfolds)
Пример #4
0
from hw1 import load_iris_data, cross_validate, knn, nb

(XX,yy,y)=load_iris_data()

classfiers_to_cv=[("kNN",knn),("Naive Bayes",nb)]

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,150] :
       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 "Highest Accuracy: fold <<%s>> :: <<%s>>" % (best_k, best_cv_a)

Пример #5
0
from hw1 import load_iris_data, cross_validate, knn, nb
# Imports functions and opject definitions from hw1.py

(iris_petal_measurements,iris_classes,iris_classnames)=load_iris_data()

classfiers_to_cv=[("kNN",knn),("Naive Bayes",nb)]

for (c_label, classifer) in classfiers_to_cv :

    print
    print "---> %s <---" % c_label

    best_k=0
    best_cv_a=0
    foldsizes=[2,3,5,10,15,30,50,75,150] 
    #These fold sizes are evenly divisible into the dataset intentionally

    for k_f in foldsizes :
       cv_a = cross_validate(iris_petal_measurements, iris_classes, classifer, k_fold=k_f)
       if cv_a >  best_cv_a :
            best_cv_a=cv_a
            best_k=k_f

       print "foldsize <<%s>> :: test accuracy <<%s>>" % (k_f, cv_a)


    print "Highest Accuracy: fold <<%s>> :: <<%s>>" % (best_k, best_cv_a)