Packages

class KNN_Predictor extends PredictorMat

The KNN_Predictor class is used to predict a response value for new vector 'z'. It works by finding its 'kappa' nearest neighbors. These neighbors essentially vote according to their prediction. The consensus is the average individual predictions for 'z'. Using a distance metric, the 'kappa' vectors nearest to 'z' are found in the training data, which are stored row-wise in data matrix 'x'. The corresponding response values are given in the vector 'y', such that the response value for vector 'x(i)' is given by 'y(i)'.

Linear Supertypes
PredictorMat, Error, Predictor, Fit, AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. KNN_Predictor
  2. PredictorMat
  3. Error
  4. Predictor
  5. Fit
  6. AnyRef
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new KNN_Predictor(x: MatriD, y: VectoD, fname_: Strings = null, hparam: HyperParameter = KNN_Predictor.hp)

    x

    the vectors/points of predictor data stored as rows of a matrix

    y

    the response value for each vector in x

    fname_

    the names for all features/variables

    hparam

    the number of nearest neighbors to consider

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. val b: VectoD
    Attributes
    protected
    Definition Classes
    Predictor
  6. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  7. def crossVal(k: Int, rando: Boolean): Unit

    The 'crossVal' abstract method must be coded in implementing classes to call the above 'crossValidate' method.

    The 'crossVal' abstract method must be coded in implementing classes to call the above 'crossValidate' method. The 'algor' parameter may be specified as a lambda function to create the prediction algorithm.

    k

    the number of crosses and cross-validations (defaults to 10x).

    rando

    flag for using randomized cross-validation

    Definition Classes
    KNN_PredictorPredictorMat
  8. def crossValidate(algor: (MatriD, VectoD) ⇒ PredictorMat, k: Int = 10, rando: Boolean = true): Array[Statistic]
    Definition Classes
    PredictorMat
  9. def diagnose(e: VectoD, w: VectoD = null, yp: VectoD = null, y_: VectoD = y): Unit

    Given the error/residual vector, compute the quality of fit measures.

    Given the error/residual vector, compute the quality of fit measures.

    e

    the corresponding m-dimensional error vector (y - yp)

    w

    the weights on the instances

    yp

    the predicted response vector (x * b)

    Definition Classes
    Fit
  10. def distance(x: VectoD, z: VectoD): Double

    Compute a distance metric between vectors/points 'x' and 'z'.

    Compute a distance metric between vectors/points 'x' and 'z'. The squared Euclidean norm used for efficiency, but may use other norms.

    x

    the first vector/point

    z

    the second vector/point

  11. val e: VectoD
    Attributes
    protected
    Definition Classes
    Predictor
  12. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  13. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  14. def eval(xx: MatriD, yy: VectoD): Unit

    Evaluate by diagnose the error.

    Evaluate by diagnose the error.

    xx

    the data matrix used in prediction

    yy

    the actual response vector

    Definition Classes
    KNN_PredictorPredictorMatPredictor
  15. def eval(): Unit

    Evaluate by diagnose the error.

    Evaluate by diagnose the error.

    Definition Classes
    KNN_PredictorPredictorMatPredictor
  16. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def fit: VectoD

    Return the quality of fit including 'rSq', 'sst', 'sse', 'mse0', rmse', 'mae', 'df._2', 'rBarSq', 'fStat', 'aic', 'bic'.

    Return the quality of fit including 'rSq', 'sst', 'sse', 'mse0', rmse', 'mae', 'df._2', 'rBarSq', 'fStat', 'aic', 'bic'. Note, if 'sse > sst', the model introduces errors and the 'rSq' may be negative, otherwise, R^2 ('rSq') ranges from 0 (weak) to 1 (strong). Note that 'rSq' is the number 5 measure. Override to add more quality of fit measures.

    Definition Classes
    Fit
  18. def fitLabel: Seq[String]

    Return the labels for the quality of fit measures.

    Return the labels for the quality of fit measures. Override to add more quality of fit measures.

    Definition Classes
    Fit
  19. def fitMap: Map[String, String]

    Build a map of quality of fit measures (use of LinedHashMap makes it ordered).

    Build a map of quality of fit measures (use of LinedHashMap makes it ordered). Override to add more quality of fit measures.

    Definition Classes
    Fit
  20. final def flaw(method: String, message: String): Unit
    Definition Classes
    Error
  21. var fname: Strings
    Attributes
    protected
    Definition Classes
    PredictorMat
  22. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  23. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  24. def hparameter: HyperParameter

    Return the hyper-parameters.

    Return the hyper-parameters.

    Definition Classes
    PredictorMat
  25. val index_rSq: Int
    Definition Classes
    Fit
  26. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  27. val k: Int
    Attributes
    protected
    Definition Classes
    PredictorMat
  28. def kNearest(z: VectoD): Unit

    Find the 'kappa' nearest neighbors (top-'kappa') to vector 'z' and store in the 'topK' array.

    Find the 'kappa' nearest neighbors (top-'kappa') to vector 'z' and store in the 'topK' array. Break ties by flipping a fair coin.

    z

    the vector used for prediction

  29. val m: Int
    Attributes
    protected
    Definition Classes
    PredictorMat
  30. def mse_: Double

    Return the mean of squares for error (sse / df._2).

    Return the mean of squares for error (sse / df._2). Must call diagnose first.

    Definition Classes
    Fit
  31. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  32. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  33. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  34. def parameter: VectoD

    Return the vector of parameter/coefficient values.

    Return the vector of parameter/coefficient values.

    Definition Classes
    Predictor
  35. def predict(z: VectoD): Double

    Given a new point/vector 'z', predict its response value based on the actual response values of its 'kappa' nearest neighbors.

    Given a new point/vector 'z', predict its response value based on the actual response values of its 'kappa' nearest neighbors.

    z

    the vector to predict

    Definition Classes
    KNN_PredictorPredictorMatPredictor
  36. def predict(z: MatriD = x): VectoD

    Predict the value of 'y = f(z)' by evaluating the formula 'y = b dot z', for each row of matrix 'z'.

    Predict the value of 'y = f(z)' by evaluating the formula 'y = b dot z', for each row of matrix 'z'.

    z

    the new matrix to predict

    Definition Classes
    PredictorMat
  37. def predict(z: VectoI): Double

    Given a new discrete data vector z, predict the y-value of f(z).

    Given a new discrete data vector z, predict the y-value of f(z).

    z

    the vector to use for prediction

    Definition Classes
    Predictor
  38. def reset(): Unit

    Reset or re-initialize 'topK' and counters.

  39. def resetDF(df_update: (Double, Double)): Unit

    Reset the degrees of freedom to the new updated values.

    Reset the degrees of freedom to the new updated values. For some models, the degrees of freedom is not known until after the model is built.

    df_update

    the updated degrees of freedom

    Definition Classes
    Fit
  40. def residual: VectoD

    Return the vector of residuals/errors.

    Return the vector of residuals/errors.

    Definition Classes
    Predictor
  41. def sumCoeff(b: VectoD, stdErr: VectoD = null): String

    Produce the summary report portion for the cofficients.

    Produce the summary report portion for the cofficients.

    b

    the parameters/coefficients for the model

    Definition Classes
    Fit
  42. def summary(): String

    Compute and return summary diagostics for the regression model.

    Compute and return summary diagostics for the regression model.

    Definition Classes
    PredictorMat
  43. def summary(b: VectoD, stdErr: VectoD = null, show: Boolean = false): String

    Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.

    Produce a summary report with diagnostics for each predictor 'x_j' and the overall quality of fit.

    b

    the parameters/coefficients for the model

    show

    flag indicating whether to print the summary

    Definition Classes
    Fit
  44. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  45. def toString(): String
    Definition Classes
    AnyRef → Any
  46. def train(itest: IndexedSeq[Int]): KNN_Predictor

    Training involves resetting the data structures before each prediction.

    Training involves resetting the data structures before each prediction. It uses lazy training, so most of it is done during prediction.

    itest

    the indices of the test data

  47. def train(yy: VectoD): KNN_Predictor

    Training involves resetting the data structures before each prediction.

    Training involves resetting the data structures before each prediction. It uses lazy training, so most of it is done during prediction.

    yy

    the response values

    Definition Classes
    KNN_PredictorPredictorMatPredictor
  48. def train(): PredictorMat

    Given a set of data vectors 'x's and their corresponding responses 'y's, passed into the implementing class, train the prediction function 'y = f(x)' by fitting its parameters.

    Given a set of data vectors 'x's and their corresponding responses 'y's, passed into the implementing class, train the prediction function 'y = f(x)' by fitting its parameters.

    Definition Classes
    PredictorMat
  49. def train2(yy: VectoD = y): PredictorMat
    Definition Classes
    PredictorMat
  50. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  51. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  52. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @throws( ... )
  53. val x: MatriD
    Attributes
    protected
    Definition Classes
    PredictorMat
  54. val y: VectoD
    Attributes
    protected
    Definition Classes
    PredictorMat

Inherited from PredictorMat

Inherited from Error

Inherited from Predictor

Inherited from Fit

Inherited from AnyRef

Inherited from Any

Ungrouped