Skip to content

Commit a7ac029

Browse files
committed
fix bugs in FS charts for model.seq
1 parent fc86c91 commit a7ac029

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

R/forward_selection_by_rank_class.R

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -122,21 +122,22 @@ setMethod(f="run",
122122
if (is(models(I),'model_OR_model.seq'))
123123
{ # if a model or list then apply the metric
124124

125-
k=length(unique((results$no_features)))
125+
k=length(searchlist)
126126
ts.metric=numeric(k)
127127
for (i in 1:k)
128128
{
129-
ts=results[results$no_features==i,]
129+
ts=results[results$no_features==searchlist[i],]
130130
MET=calculate(MET,ts$actual,ts$predicted)
131131
ts.metric[i]=value(MET)
132132
}
133133

134134
value=ts.metric
135-
135+
df=data.frame(metric=name(MET),mean=value,sd=NA)
136136
} else
137137
{
138138
# if not a model or list then the metric has already been applied, we just need to choose the optimum
139139
value=results$mean
140+
df=results
140141
}
141142

142143
# locate optimum using a loess fit
@@ -152,6 +153,7 @@ setMethod(f="run",
152153
lo_var_ind=searchlist[lo]
153154
output.value(I,'chosen_vars')=O[R<=lo_var_ind]
154155
output.value(I,'smoothed')=smoothed25
156+
output.value(I,'metric')=df
155157

156158
return(I)
157159
}
@@ -187,12 +189,36 @@ eval_loess=function(x,X,Y,k=10,p=0.66)
187189

188190
#' forward_selection_plot
189191
#'
190-
#' plots the result of the evaluated models against the values the number of features within the search range.
192+
#' Plots the result of the evaluated models against the values the number of
193+
#' features within the search range for forward_selection_by_rank objects.
191194
#'
192195
#' @import struct
193196
#' @export fs_line
194197
#' @examples
198+
#' # some data
199+
#' D = sbcms_dataset(filtered=TRUE)
200+
#'
201+
#' # normalise, impute and scale then remove QCs
202+
#' P = pqn_norm(qc_label='QC',factor_name='class') +
203+
#' knn_impute(neighbours=5) +
204+
#' glog_transform(qc_label='QC',factor_name='class') +
205+
#' filter_smeta(mode='exclude',levels='QC',factor_name='class')
206+
#' P = method.apply(P,D)
207+
#' D = predicted(P)
208+
#'
209+
#' # forward selection using a PLSDA model
210+
#' M = forward_selection_byrank(factor_name='class',
211+
#' min_no_vars=2,
212+
#' max_no_vars=11,
213+
#' variable_rank=1:2063) *
214+
#' (mean_centre() + PLSDA(number_components=1,
215+
#' factor_name='class'))
216+
#' M = run(M,D,balanced_accuracy())
217+
#'
218+
#' # chart
195219
#' C = fs_line()
220+
#' chart.plot(C,M)
221+
#'
196222
fs_line<-setClass(
197223
"fs_line",
198224
contains='chart',
@@ -207,7 +233,7 @@ setMethod(f="chart.plot",
207233
signature=c("fs_line",'forward_selection_byrank'),
208234
definition=function(obj,dobj)
209235
{
210-
A=result(dobj)
236+
A=dobj$metric
211237
A$smoothed=output.value(dobj,'smoothed')
212238
opt=length(output.value(dobj,'chosen_vars'))
213239
A$values=output.value(dobj,'searchlist')

man/fs_line-class.Rd

Lines changed: 25 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)