Git Product home page Git Product logo

dalex2's People

Contributors

byrolew avatar pbiecek avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

dalex2's Issues

yhat(model) and yhat(model, newdata) return different results on the same data

Hi,

Code below compares output from two calls to yhat function after model has been trained with randomForest. First is raw call, another additionally uses newdata parameter. When newdata is supplied with the same data that randomForest has been trained on, the output is different, although it should be the same.

For comparison, I also provide output directly from randomForest's votes object which apparently contains the same information as raw yhat call, therefore the problem appears to be only when newdata is supplied.

library(tidyverse)
#> -- Attaching packages ------------------------------------------------------------------------------------------------------------ tidyverse 1.2.1 --
#> <U+221A> ggplot2 2.2.1     <U+221A> purrr   0.2.4
#> <U+221A> tibble  1.4.1     <U+221A> dplyr   0.7.4
#> <U+221A> tidyr   0.7.2     <U+221A> stringr 1.2.0
#> <U+221A> readr   1.1.1     <U+221A> forcats 0.2.0
#> -- Conflicts --------------------------------------------------------------------------------------------------------------- tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()
library(DALEX2)
#> Welcome to DALEX2 (version: 0.9).
#> 
#> Dołączanie pakietu: 'DALEX2'
#> Następujący obiekt został zakryty z 'package:dplyr':
#> 
#>     explain
library(randomForest)
#> randomForest 4.6-12
#> Type rfNews() to see new features/changes/bug fixes.
#> 
#> Dołączanie pakietu: 'randomForest'
#> Następujący obiekt został zakryty z 'package:dplyr':
#> 
#>     combine
#> Następujący obiekt został zakryty z 'package:ggplot2':
#> 
#>     margin

X <- HR %>% select(-status, -gender)
Y <- HR %>% select(status) %>% unlist()
Y <- if_else(Y=="fired",1,0) %>% as.factor(.)

rf.model <- randomForest(x = X, y = Y, ntree = 500, localImp = TRUE)

f1 <- yhat(rf.model)
f2 <- yhat(rf.model, newdata=X)
f3 <- rf.model$votes

cbind(f1[,2],f2[,2],f3[,2]) %>% as_data_frame %>% head(.)
#> # A tibble: 6 x 3
#>       V1     V2     V3
#>    <dbl>  <dbl>  <dbl>
#> 1 0.872  0.938  0.872 
#> 2 0.982  0.994  0.982 
#> 3 0.983  0.994  0.983 
#> 4 0.764  0.866  0.764 
#> 5 0.0585 0.0220 0.0585
#> 6 0.624  0.794  0.624

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.