Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit15fe41b

Browse files
committed
new interface for relief
1 parentfee2300 commit15fe41b

File tree

3 files changed

+51
-10
lines changed

3 files changed

+51
-10
lines changed

‎R/relief.R‎

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@
66

77
#' RReliefF filter
88
#'
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
1315
#'
1416
#' @description The algorithm finds weights of continuous and discrete attributes basing on a distance between instances.
1517
#'
@@ -34,7 +36,38 @@
3436
#' f <- as.simple.formula(subset, "Species")
3537
#' print(f)
3638
#'
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) {
3871
# uses parent.env
3972
find_neighbours<-function(instance_idx) {
4073
instance=new_data[instance_idx,,drop=FALSE]

‎man/relief.Rd‎

Lines changed: 9 additions & 5 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎tests/testthat/test-relief.R‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ if (require("FSelector")) {
44
test_that("Basic comparsion with FSelector", {
55
fs<-withr::with_seed(123,FSelector::relief(Species~.,iris))
66
fs2<-withr::with_seed(123, relief(Species~.,iris))
7+
8+
fs3<-withr::with_seed(123, relief(x=iris[-5],y=iris$Species))
9+
710
expect_equal(fs,fs2)
11+
expect_equal(fs,fs3)
812
})
913
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp