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

ggplot.train level plots has incorrectly reordered axis #620

Closed
MarekOzana opened this issue Mar 25, 2017 · 2 comments
Closed

ggplot.train level plots has incorrectly reordered axis #620

MarekOzana opened this issue Mar 25, 2017 · 2 comments

Comments

@MarekOzana
Copy link

@MarekOzana MarekOzana commented Mar 25, 2017

It seems that ggplot.train is converting the tuneGrid parameters into factors and thus sometimes creating cases when numerical order is broken. Consequently the charts have incorrect axis order.
e.g. instead of 0.0001, 0.01, 1 it produces 1e-2, 1e-4, 1 (string order not number order).

Minimal, reproducible example:

library(caret)
data(mtcars)
m <- train(mpg ~ cyl + disp,
           data = mtcars,
           method="svmRadial",
           tuneGrid = expand.grid(C=1:2, sigma=c(0.0001, 0.01, 1)))
ggplot(m, plotType="level")

the produced chart has incorrectly ordered sigma axes.

Session Info:

>sessionInfo()
R version 3.3.2 (2016-10-31)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252   
[3] LC_MONETARY=English_United States.1252 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] kernlab_0.9-25  caret_6.0-73    ggplot2_2.2.1   lattice_0.20-34

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.10       magrittr_1.5       splines_3.3.2      MASS_7.3-45        munsell_0.4.3     
 [6] colorspace_1.3-2   foreach_1.4.3      minqa_1.2.4        stringr_1.2.0      car_2.1-4         
[11] plyr_1.8.4         tools_3.3.2        parallel_3.3.2     nnet_7.3-12        pbkrtest_0.4-7    
[16] grid_3.3.2         gtable_0.2.0       nlme_3.1-131       mgcv_1.8-17        quantreg_5.29     
[21] MatrixModels_0.4-1 iterators_1.0.8    digest_0.6.12      lme4_1.1-12        lazyeval_0.2.0    
[26] assertthat_0.1     tibble_1.2         Matrix_1.2-8       nloptr_1.0.4       reshape2_1.4.2    
[31] ModelMetrics_1.1.0 codetools_0.2-15   labeling_0.3       stringi_1.1.3      compiler_3.3.2    
[36] scales_0.4.1       stats4_3.3.2       SparseM_1.76      
@m-dz
Copy link
Contributor

@m-dz m-dz commented Mar 29, 2017

I think I have a fix ready, just need to figure out how to submit it...

In the meantime, one more example:

x <- train(mpg ~ cyl + disp,
           data = mtcars,
           method="xgbTree",
           tuneGrid = expand.grid(
             nrounds=c(20),
             max_depth=c(2),
             eta = c(0.0001, 0.01, 1),
             gamma = c(0.0001, 0.01, 1),
             colsample_bytree=c(0.0001, 0.01, 1),
             min_child_weight = 1,
             subsample = 1
           ))

ggplot(x, plotType="level", nameInStrip = TRUE)
m-dz added a commit to m-dz/caret that referenced this issue Mar 29, 2017
If values are numeric add sorted levels to factors to fix ggplot axes values.
@m-dz
Copy link
Contributor

@m-dz m-dz commented Mar 29, 2017

I have added a pull request #624 as an attempt to fix this issue. Both @MarekOzana's and my examples produce expected plots. I hope I did not break anything...

m-dz added a commit to m-dz/caret that referenced this issue Apr 4, 2017
@topepo topepo closed this in 7f1cdba Apr 5, 2017
topepo added a commit that referenced this issue Apr 5, 2017
Add sorted levels to factors (attempt to fix #620)
topepo added a commit that referenced this issue Apr 13, 2017
Amendments and additional test for PR #624 (issue #620)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.