|
6 | 6 |
|
7 | 7 | #' RReliefF filter |
8 | 8 | #' |
9 | | -#' @param formula a symbolic description of a model |
10 | | -#' @param data data to process |
11 | | -#' @param neighbours.count number of neighbours to find for every sampled instance |
12 | | -#' @param sample.size number of instances to sample |
| 9 | +#' @param formula An object of class \link{formula} with model description. |
| 10 | +#' @param data A \link{data.frame} accompanying formula. |
| 11 | +#' @param x A \link{data.frame} with attributes. |
| 12 | +#' @param y A vector with response variable. |
| 13 | +#' @param neighboursCount number of neighbours to find for every sampled instance |
| 14 | +#' @param sampleSize number of instances to sample |
13 | 15 | #' |
14 | 16 | #' @description The algorithm finds weights of continuous and discrete attributes basing on a distance between instances. |
15 | 17 | #' |
|
34 | 36 | #' f <- as.simple.formula(subset, "Species") |
35 | 37 | #' print(f) |
36 | 38 | #' |
37 | | -relief<-function(formula,data,neighbours.count=5,sample.size=10) { |
| 39 | +relief<-function(formula,data,x,y,neighboursCount=5,sampleSize=10) { |
| 40 | + |
| 41 | +if (!xor( |
| 42 | + all(!missing(x),!missing(y)), |
| 43 | + all(!missing(formula),!missing(data)))) { |
| 44 | + stop(paste("Please specify both `x = attributes, y = response`,", |
| 45 | +"XOR use both `formula = response ~ attributes, data = dataset")) |
| 46 | + } |
| 47 | +if (sum(!missing(x),!missing(y),!missing(formula),!missing(data))>2){ |
| 48 | + stop(paste("Please specify both `x = attributes, y = response`,", |
| 49 | +"XOR use both `formula = response ~ attributes, data = dataset")) |
| 50 | + } |
| 51 | + |
| 52 | +if (!missing(x)&&!missing(y)) { |
| 53 | +if (class(x)=="formula") { |
| 54 | + stop(paste("Please use `formula = response ~ attributes, data = dataset`", |
| 55 | +"interface instead of `x = formula`.")) |
| 56 | + } |
| 57 | + |
| 58 | +data<- cbind(ReliefResponseVariable=y,x) |
| 59 | +formula<-ReliefResponseVariable~. |
| 60 | +return(.relief(formula,data,neighboursCount,sampleSize)) |
| 61 | + } |
| 62 | + |
| 63 | +if (!missing(formula)&&!missing(data)) { |
| 64 | +return(.relief(formula,data,neighboursCount,sampleSize)) |
| 65 | + } |
| 66 | + |
| 67 | +} |
| 68 | + |
| 69 | + |
| 70 | +.relief<-function(formula,data,neighbours.count=5,sample.size=10) { |
38 | 71 | # uses parent.env |
39 | 72 | find_neighbours<-function(instance_idx) { |
40 | 73 | instance=new_data[instance_idx,,drop=FALSE] |
|