r - Data split for train test for a model -


i have 2 vectors , data frame. run random generator obtain split training , test model. (true train while false test sets), if run multiple times number of true false changes in number (false ranges 4 8) in position. example, actual data frame larger.

x <- c(1,2,3,5,4,1,2,3,5,7,4,2,1,5,6,8,5,3,2,4,6,8,9,0,2) y <- c(3,5,7,8,4,2,2,5,4,7,9,0,0,7,6,4,2,2,1,4,6,8,9,0,0) x <- data.frame(x,y)  runif(nrow (x)) <= 0.75 [1]  true  true  true false  true  true  true  true  true false  true  true  true false  true   false  true  true  true  true  true  true false  true  true 

i find function or able instruct generation of split true , false sequentially elements named false found @ end while prior elements should true. should yield in line example below.

[1]  true true  true  true  true  true  true  true true true  true  true  true  true  true   true  true  true  true false  false false  false false  false 

i have looked functions without luck function serves purpose createtimeslices in caret package implies significant changes in model difficult implement.

on hand have expression below obtain false @ end once while rest random expected, can not come out expression produce sequentially number of false instruted split found in last possitions while prior yields true in example above.

s<- runif(nrow (x)) <=  0.75 s[length(s)] <- false  while(s[length(s)] [!false]) { s<-runif(nrow (x)) <=  0.75} train<-print(s) 

any welcomed

many

maybe i'm misunderstanding, couldn't

s <- runif(nrow(x)) <= 0.75  sort(s,decreasing = true)  [1]  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true [19]  true  true  true false false false false 

that gives (approximately) 75% true values, @ front of vector.

correction?

it looks want first 75% of rows (based on comment above). in case, i'd this:

crit <- floor(nrow(x) * 0.75) train <- seq_len(nrow(x)) < crit train   [1]  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true  true false [19] false false false false false false false 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -