Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "predict" for binr #1

Merged
merged 5 commits into from
Dec 28, 2017
Merged

Implement "predict" for binr #1

merged 5 commits into from
Dec 28, 2017

Conversation

smsaladi
Copy link

@smsaladi smsaladi commented Feb 8, 2017

I found your package and functionality quite useful. It would be much easier to use if there were an associated predict method. This would allow calculating cut points on some dataset and then applying these cuts/featurization to new data.

I went ahead and implemented this. In the process, I needed to create some S3 methods.

Because of a change in roxygen2 behavior, I had to make other changes to the documentation code. I tried to commit in logical way to separate this. Also, there were some end of line spaces. Rstudio and atom both clear these, so I committed this separately as well.

Let me know what you think.

> bindata <- bins(iris[,1:4], 5, 5)
> predict(bindata, iris[,1:4]) %>% head
  Sepal.Length Sepal.Width Petal.Length Petal.Width
1            2           3            1           1
2            1           2            1           1
3            1           2            1           1
4            1           2            1           1
5            1           3            1           1
6            2           3            2           2
> 
> withNA <- iris[,1:4]
> withNA[2,1] <- NA
> head(withNA)
  Sepal.Length Sepal.Width Petal.Length Petal.Width
1          5.1         3.5          1.4         0.2
2           NA         3.0          1.4         0.2
3          4.7         3.2          1.3         0.2
4          4.6         3.1          1.5         0.2
5          5.0         3.6          1.4         0.2
6          5.4         3.9          1.7         0.4
> 
> predict(bindata, withNA, labels = TRUE) %>% head
  Sepal.Length Sepal.Width Petal.Length  Petal.Width
1  (5.05,5.65] (3.25, Inf]  (-Inf,1.55] (-Inf,0.249]
2         [NA] (2.95,3.25]  (-Inf,1.55] (-Inf,0.249]
3  (-Inf,5.05] (2.95,3.25]  (-Inf,1.55] (-Inf,0.249]
4  (-Inf,5.05] (2.95,3.25]  (-Inf,1.55] (-Inf,0.249]
5  (-Inf,5.05] (3.25, Inf]  (-Inf,1.55] (-Inf,0.249]
6  (5.05,5.65] (3.25, Inf]  (1.55,4.35] (0.249,1.25]
> 
> predict(bindata, withNA) %>% head
  Sepal.Length Sepal.Width Petal.Length Petal.Width
1            2           3            1           1
2            6           2            1           1
3            1           2            1           1
4            1           2            1           1
5            1           3            1           1
6            2           3            2           2

@sizrailev sizrailev merged commit 7bb1a12 into jabiru:master Dec 28, 2017
@sizrailev
Copy link

Hi @smsaladi, thanks very much for contributing and for being so thoughtful about separate commits! Your PR is now merged and I will find time to push it to CRAN in the next few weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants