Package ML :: Package KNN :: Module CrossValidate
[hide private]
[frames] | no frames]

Module CrossValidate

source code

handles doing cross validation with k-nearest neighbors model

and evaluation of individual models



Functions [hide private]
 
makeClassificationModel(numNeigh, attrs, distFunc) source code
 
makeRegressionModel(numNeigh, attrs, distFunc) source code
 
CrossValidate(knnMod, testExamples, appendExamples=0)
Determines the classification error for the testExamples **Arguments** - tree: a decision tree (or anything supporting a _ClassifyExample()_ method) - testExamples: a list of examples to be used for testing - appendExamples: a toggle which is passed along to the tree as it does the classification.
source code
 
CrossValidationDriver(examples, attrs, nPossibleValues, numNeigh, modelBuilder=<function makeClassificationModel at 0x9c93a3c>, distFunc=<function EuclideanDist at 0x9c93534>, holdOutFrac=0.3, silent=0, calcTotalError=0, **kwargs)
Driver function for building a KNN model of a specified type...
source code
Variables [hide private]
  Complex0 = 'F'
  Complex16 = 'F'
  Complex32 = 'F'
  Complex64 = 'D'
  Complex8 = 'F'
  Float0 = 'f'
  Float16 = 'f'
  Float32 = 'f'
  Float64 = 'd'
  Float8 = 'f'
  Int0 = '1'
  Int16 = 's'
  Int32 = 'i'
  Int8 = '1'
  absolute = <ufunc 'absolute'>
  add = <ufunc 'add'>
  arccos = <ufunc 'arccos'>
  arccosh = <ufunc 'arccosh'>
  arcsin = <ufunc 'arcsin'>
  arcsinh = <ufunc 'arcsinh'>
  arctan = <ufunc 'arctan'>
  arctan2 = <ufunc 'arctan2'>
  arctanh = <ufunc 'arctanh'>
  bitwise_and = <ufunc 'bitwise_and'>
  bitwise_or = <ufunc 'bitwise_or'>
  bitwise_xor = <ufunc 'bitwise_xor'>
  ceil = <ufunc 'ceil'>
  conjugate = <ufunc 'conjugate'>
  cos = <ufunc 'cos'>
  cosh = <ufunc 'cosh'>
  divide = <ufunc 'divide'>
  divide_safe = <ufunc 'divide_safe'>
  e = 2.71828182846
  equal = <ufunc 'equal'>
  exp = <ufunc 'exp'>
  fabs = <ufunc 'fabs'>
  floor = <ufunc 'floor'>
  floor_divide = <ufunc 'floor_divide'>
  fmod = <ufunc 'fmod'>
  greater = <ufunc 'greater'>
  greater_equal = <ufunc 'greater_equal'>
  hypot = <ufunc 'hypot'>
  invert = <ufunc 'invert'>
  left_shift = <ufunc 'left_shift'>
  less = <ufunc 'less'>
  less_equal = <ufunc 'less_equal'>
  log = <ufunc 'log'>
  log10 = <ufunc 'log10'>
  logical_and = <ufunc 'logical_and'>
  logical_not = <ufunc 'logical_not'>
  logical_or = <ufunc 'logical_or'>
  logical_xor = <ufunc 'logical_xor'>
  maximum = <ufunc 'maximum'>
  minimum = <ufunc 'minimum'>
  multiply = <ufunc 'multiply'>
  negative = <ufunc 'negative'>
  not_equal = <ufunc 'not_equal'>
  pi = 3.14159265359
  power = <ufunc 'power'>
  remainder = <ufunc 'remainder'>
  right_shift = <ufunc 'right_shift'>
  sin = <ufunc 'sin'>
  sinh = <ufunc 'sinh'>
  sqrt = <ufunc 'sqrt'>
  subtract = <ufunc 'subtract'>
  tan = <ufunc 'tan'>
  tanh = <ufunc 'tanh'>
  true_divide = <ufunc 'true_divide'>
Function Details [hide private]

CrossValidate(knnMod, testExamples, appendExamples=0)

source code 

Determines the classification error for the testExamples

**Arguments**

  - tree: a decision tree (or anything supporting a _ClassifyExample()_ method)

  - testExamples: a list of examples to be used for testing

  - appendExamples: a toggle which is passed along to the tree as it does
    the classification. The trees can use this to store the examples they
    classify locally.

**Returns**

  a 2-tuple consisting of:
    

CrossValidationDriver(examples, attrs, nPossibleValues, numNeigh, modelBuilder=<function makeClassificationModel at 0x9c93a3c>, distFunc=<function EuclideanDist at 0x9c93534>, holdOutFrac=0.3, silent=0, calcTotalError=0, **kwargs)

source code 
Driver function for building a KNN model of a specified type

**Arguments**

  - examples: the full set of examples

  - numNeigh: number of neighbors for the KNN model (basically k in k-NN)

  - knnModel: the type of KNN model (a classification vs regression model)

  - holdOutFrac: the fraction of the data which should be reserved for the hold-out set
    (used to calculate error)

  - silent: a toggle used to control how much visual noise this makes as it goes

  - calcTotalError: a toggle used to indicate whether the classification error
    of the tree should be calculated using the entire data set (when true) or just
    the training hold out set (when false)