tidymodels / usemodels

Boilerplate Code for tidymodels
https://usemodels.tidymodels.org
Other
84 stars 6 forks source link

Usemodels+glmnet: why a classification is suggested to predict a numerical variable? #45

Open larry77 opened 8 months ago

larry77 commented 8 months ago

Please look at the reprex at the end of this issue. You can download the input data from

https://e.pcloud.link/publink/show?code=XZWXInZ683FG2Squ0bLeLRNaGnzxukG1Le7

(nothing dangerous).

I try to set up tidymodels + glmnet to predict a continuous, numerical variable ("close"), so why does usemodels give me a boilerplate for a classification model?

library(tidymodels)
library(glmnet)
#> Loading required package: Matrix
#> 
#> Attaching package: 'Matrix'
#> The following objects are masked from 'package:tidyr':
#> 
#>     expand, pack, unpack
#> Loaded glmnet 4.1-8
library(usemodels)

## get the data from
## https://e.pcloud.link/publink/show?code=XZWXInZ683FG2Squ0bLeLRNaGnzxukG1Le7

df_train <- readRDS("train_data.RDS")

df_train |> glimpse()
#> Rows: 327
#> Columns: 217
#> $ close                                  <dbl> 71.37752, 72.92498, 69.77042, 7…
#> $ high                                   <dbl> 73.50968, 73.35770, 73.56974, 7…
#> $ low                                    <dbl> 70.35861, 71.06888, 68.62396, 6…
#> $ volume                                 <dbl> 53187377, 53254101, 62337407, 5…
#> $ ad                                     <dbl> 24993412, 58111264, 24674094, 4…
#> $ obv                                    <dbl> 280903312, 334157412, 271820006…
#> $ rrt                                    <dbl> 0.04380488, 0.03169536, 0.06956…
#> $ sigmat                                 <dbl> 0.026311717, 0.019036598, 0.041…
#> $ btc_dominance                          <dbl> 46.1490, 46.2965, 46.3824, 46.2…
#> $ eth_dominance                          <dbl> 18.6197, 18.5903, 18.6252, 18.5…
#> $ active_cryptocurrencies                <int> 9108, 9102, 9095, 9110, 9103, 9…
#> $ active_exchanges                       <int> 578, 578, 578, 578, 578, 585, 5…
#> $ active_market_pairs                    <int> 63150, 63140, 63194, 63369, 634…
#> $ usd_total_market_cap                   <dbl> 1.151301e+12, 1.147889e+12, 1.1…
#> $ usd_total_volume_24h                   <dbl> 54992894975, 32983707725, 31515…
#> $ usd_total_volume_24h_reported          <dbl> 227239161079, 131151347323, 136…
#> $ usd_altcoin_market_cap                 <dbl> 619987665974, 616456746612, 625…
#> $ usd_altcoin_volume_24h                 <dbl> 29012797859, 19601618671, 17636…
#> $ usd_altcoin_volume_24h_reported        <dbl> 118356993224, 76015632985, 7440…
#> $ lag_high_04                            <dbl> 79.33371, 79.23391, 80.37833, 7…
#> $ lag_high_05                            <dbl> 80.13074, 79.33371, 79.23391, 8…
#> $ lag_high_06                            <dbl> 81.65857, 80.13074, 79.33371, 7…
#> $ lag_high_07                            <dbl> 81.85890, 81.65857, 80.13074, 7…
#> $ lag_high_08                            <dbl> 80.65517, 81.85890, 81.65857, 8…
#> $ lag_high_09                            <dbl> 75.60789, 80.65517, 81.85890, 8…
#> $ lag_high_10                            <dbl> 80.68163, 75.60789, 80.65517, 8…
#> $ lag_high_11                            <dbl> 81.51750, 80.68163, 75.60789, 8…
#> $ lag_high_12                            <dbl> 77.21347, 81.51750, 80.68163, 7…
#> $ lag_high_13                            <dbl> 72.97124, 77.21347, 81.51750, 8…
#> $ lag_high_14                            <dbl> 70.79873, 72.97124, 77.21347, 8…
#> $ lag_low_04                             <dbl> 74.83914, 73.34505, 74.64390, 7…
#> $ lag_low_05                             <dbl> 76.04362, 74.83914, 73.34505, 7…
#> $ lag_low_06                             <dbl> 77.80269, 76.04362, 74.83914, 7…
#> $ lag_low_07                             <dbl> 77.66202, 77.80269, 76.04362, 7…
#> $ lag_low_08                             <dbl> 74.06801, 77.66202, 77.80269, 7…
#> $ lag_low_09                             <dbl> 73.57610, 74.06801, 77.66202, 7…
#> $ lag_low_10                             <dbl> 72.03230, 73.57610, 74.06801, 7…
#> $ lag_low_11                             <dbl> 74.77417, 72.03230, 73.57610, 7…
#> $ lag_low_12                             <dbl> 71.17249, 74.77417, 72.03230, 7…
#> $ lag_low_13                             <dbl> 66.62366, 71.17249, 74.77417, 7…
#> $ lag_low_14                             <dbl> 64.80951, 66.62366, 71.17249, 7…
#> $ lag_volume_04                          <dbl> 67754141, 72497294, 84330280, 7…
#> $ lag_volume_05                          <dbl> 68782996, 67754141, 72497294, 8…
#> $ lag_volume_06                          <dbl> 63342139, 68782996, 67754141, 7…
#> $ lag_volume_07                          <dbl> 79006655, 63342139, 68782996, 6…
#> $ lag_volume_08                          <dbl> 76908698, 79006655, 63342139, 6…
#> $ lag_volume_09                          <dbl> 58920757, 76908698, 79006655, 6…
#> $ lag_volume_10                          <dbl> 92071978, 58920757, 76908698, 7…
#> $ lag_volume_11                          <dbl> 115506512, 92071978, 58920757, …
#> $ lag_volume_12                          <dbl> 93444168, 115506512, 92071978, …
#> $ lag_volume_13                          <dbl> 69587249, 93444168, 115506512, …
#> $ lag_volume_14                          <dbl> 88051180, 69587249, 93444168, 1…
#> $ lag_ad_04                              <dbl> 128555246, 104571541, 97276212,…
#> $ lag_ad_05                              <dbl> 69650201, 128555246, 104571541,…
#> $ lag_ad_06                              <dbl> 134464383, 69650201, 128555246,…
#> $ lag_ad_07                              <dbl> 138734037, 134464383, 69650201,…
#> $ lag_ad_08                              <dbl> 212805675, 138734037, 134464383…
#> $ lag_ad_09                              <dbl> 135896977, 212805675, 138734037…
#> $ lag_ad_10                              <dbl> 108597216, 135896977, 212805675…
#> $ lag_ad_11                              <dbl> 158515979, 108597216, 135896977…
#> $ lag_ad_12                              <dbl> 117801450, 158515979, 108597216…
#> $ lag_ad_13                              <dbl> 57444209, 117801450, 158515979,…
#> $ lag_ad_14                              <dbl> -12137818, 57444209, 117801450,…
#> $ lag_obv_04                             <dbl> 393653217, 321155923, 405486204…
#> $ lag_obv_05                             <dbl> 325899076, 393653217, 321155923…
#> $ lag_obv_06                             <dbl> 394682072, 325899076, 393653217…
#> $ lag_obv_07                             <dbl> 331339933, 394682072, 325899076…
#> $ lag_obv_08                             <dbl> 410346588, 331339933, 394682072…
#> $ lag_obv_09                             <dbl> 333437890, 410346588, 331339933…
#> $ lag_obv_10                             <dbl> 274517132, 333437890, 410346588…
#> $ lag_obv_11                             <dbl> 366589110, 274517132, 333437890…
#> $ lag_obv_12                             <dbl> 251082598, 366589110, 274517132…
#> $ lag_obv_13                             <dbl> 157638429, 251082598, 366589110…
#> $ lag_obv_14                             <dbl> 88051180, 157638429, 251082598,…
#> $ lag_rrt_04                             <dbl> 0.05830557, 0.07719096, 0.07398…
#> $ lag_rrt_05                             <dbl> 0.05234049, 0.05830557, 0.07719…
#> $ lag_rrt_06                             <dbl> 0.04836142, 0.05234049, 0.05830…
#> $ lag_rrt_07                             <dbl> 0.05261853, 0.04836142, 0.05234…
#> $ lag_rrt_08                             <dbl> 0.08514770, 0.05261853, 0.04836…
#> $ lag_rrt_09                             <dbl> 0.02723883, 0.08514770, 0.05261…
#> $ lag_rrt_10                             <dbl> 0.11327487, 0.02723883, 0.08514…
#> $ lag_rrt_11                             <dbl> 0.08629151, 0.11327487, 0.02723…
#> $ lag_rrt_12                             <dbl> 0.08142247, 0.08629151, 0.11327…
#> $ lag_rrt_13                             <dbl> 0.09094291, 0.08142247, 0.08629…
#> $ lag_rrt_14                             <dbl> 0.08833119, 0.09094291, 0.08142…
#> $ lag_sigmat_04                          <dbl> 0.035025991, 0.046380937, 0.044…
#> $ lag_sigmat_05                          <dbl> 0.031440848, 0.035025991, 0.046…
#> $ lag_sigmat_06                          <dbl> 0.029049653, 0.031440848, 0.035…
#> $ lag_sigmat_07                          <dbl> 0.031607945, 0.029049653, 0.031…
#> $ lag_sigmat_08                          <dbl> 0.051167334, 0.031607945, 0.029…
#> $ lag_sigmat_09                          <dbl> 0.016359595, 0.051167334, 0.031…
#> $ lag_sigmat_10                          <dbl> 0.068101375, 0.016359595, 0.051…
#> $ lag_sigmat_11                          <dbl> 0.051855526, 0.068101375, 0.016…
#> $ lag_sigmat_12                          <dbl> 0.048926220, 0.051855526, 0.068…
#> $ lag_sigmat_13                          <dbl> 0.054654471, 0.048926220, 0.051…
#> $ lag_sigmat_14                          <dbl> 0.053082816, 0.054654471, 0.048…
#> $ lag_btc_dominance_04                   <dbl> 46.5431, 46.0186, 46.0846, 46.1…
#> $ lag_btc_dominance_05                   <dbl> 46.0860, 46.5431, 46.0186, 46.0…
#> $ lag_btc_dominance_06                   <dbl> 45.4814, 46.0860, 46.5431, 46.0…
#> $ lag_btc_dominance_07                   <dbl> 45.4509, 45.4814, 46.0860, 46.5…
#> $ lag_btc_dominance_08                   <dbl> 44.4637, 45.4509, 45.4814, 46.0…
#> $ lag_btc_dominance_09                   <dbl> 44.2288, 44.4637, 45.4509, 45.4…
#> $ lag_btc_dominance_10                   <dbl> 43.7508, 44.2288, 44.4637, 45.4…
#> $ lag_btc_dominance_11                   <dbl> 43.4954, 43.7508, 44.2288, 44.4…
#> $ lag_btc_dominance_12                   <dbl> 42.2199, 43.4954, 43.7508, 44.2…
#> $ lag_btc_dominance_13                   <dbl> 41.8573, 42.2199, 43.4954, 43.7…
#> $ lag_btc_dominance_14                   <dbl> 41.4604, 41.8573, 42.2199, 43.4…
#> $ lag_eth_dominance_04                   <dbl> 18.4221, 18.6836, 18.5691, 18.7…
#> $ lag_eth_dominance_05                   <dbl> 18.5857, 18.4221, 18.6836, 18.5…
#> $ lag_eth_dominance_06                   <dbl> 18.8245, 18.5857, 18.4221, 18.6…
#> $ lag_eth_dominance_07                   <dbl> 18.8142, 18.8245, 18.5857, 18.4…
#> $ lag_eth_dominance_08                   <dbl> 18.8548, 18.8142, 18.8245, 18.5…
#> $ lag_eth_dominance_09                   <dbl> 19.0374, 18.8548, 18.8142, 18.8…
#> $ lag_eth_dominance_10                   <dbl> 19.0789, 19.0374, 18.8548, 18.8…
#> $ lag_eth_dominance_11                   <dbl> 19.1327, 19.0789, 19.0374, 18.8…
#> $ lag_eth_dominance_12                   <dbl> 19.1986, 19.1327, 19.0789, 19.0…
#> $ lag_eth_dominance_13                   <dbl> 19.0576, 19.1986, 19.1327, 19.0…
#> $ lag_eth_dominance_14                   <dbl> 18.5970, 19.0576, 19.1986, 19.1…
#> $ lag_active_cryptocurrencies_04         <int> 9068, 9077, 9097, 9106, 9108, 9…
#> $ lag_active_cryptocurrencies_05         <int> 9059, 9068, 9077, 9097, 9106, 9…
#> $ lag_active_cryptocurrencies_06         <int> 9057, 9059, 9068, 9077, 9097, 9…
#> $ lag_active_cryptocurrencies_07         <int> 9063, 9057, 9059, 9068, 9077, 9…
#> $ lag_active_cryptocurrencies_08         <int> 9068, 9063, 9057, 9059, 9068, 9…
#> $ lag_active_cryptocurrencies_09         <int> 9052, 9068, 9063, 9057, 9059, 9…
#> $ lag_active_cryptocurrencies_10         <int> 9036, 9052, 9068, 9063, 9057, 9…
#> $ lag_active_cryptocurrencies_11         <int> 9088, 9036, 9052, 9068, 9063, 9…
#> $ lag_active_cryptocurrencies_12         <int> 9068, 9088, 9036, 9052, 9068, 9…
#> $ lag_active_cryptocurrencies_13         <int> 9070, 9068, 9088, 9036, 9052, 9…
#> $ lag_active_cryptocurrencies_14         <int> 9073, 9070, 9068, 9088, 9036, 9…
#> $ lag_active_exchanges_04                <int> 572, 572, 576, 578, 578, 578, 5…
#> $ lag_active_exchanges_05                <int> 572, 572, 572, 576, 578, 578, 5…
#> $ lag_active_exchanges_06                <int> 572, 572, 572, 572, 576, 578, 5…
#> $ lag_active_exchanges_07                <int> 572, 572, 572, 572, 572, 576, 5…
#> $ lag_active_exchanges_08                <int> 570, 572, 572, 572, 572, 572, 5…
#> $ lag_active_exchanges_09                <int> 570, 570, 572, 572, 572, 572, 5…
#> $ lag_active_exchanges_10                <int> 569, 570, 570, 572, 572, 572, 5…
#> $ lag_active_exchanges_11                <int> 569, 569, 570, 570, 572, 572, 5…
#> $ lag_active_exchanges_12                <int> 568, 569, 569, 570, 570, 572, 5…
#> $ lag_active_exchanges_13                <int> 568, 568, 569, 569, 570, 570, 5…
#> $ lag_active_exchanges_14                <int> 567, 568, 568, 569, 569, 570, 5…
#> $ lag_active_market_pairs_04             <int> 62673, 62734, 62876, 63059, 631…
#> $ lag_active_market_pairs_05             <int> 62483, 62673, 62734, 62876, 630…
#> $ lag_active_market_pairs_06             <int> 62385, 62483, 62673, 62734, 628…
#> $ lag_active_market_pairs_07             <int> 62283, 62385, 62483, 62673, 627…
#> $ lag_active_market_pairs_08             <int> 61831, 62283, 62385, 62483, 626…
#> $ lag_active_market_pairs_09             <int> 61712, 61831, 62283, 62385, 624…
#> $ lag_active_market_pairs_10             <int> 61613, 61712, 61831, 62283, 623…
#> $ lag_active_market_pairs_11             <int> 61425, 61613, 61712, 61831, 622…
#> $ lag_active_market_pairs_12             <int> 61608, 61425, 61613, 61712, 618…
#> $ lag_active_market_pairs_13             <int> 61628, 61608, 61425, 61613, 617…
#> $ lag_active_market_pairs_14             <int> 61567, 61628, 61608, 61425, 616…
#> $ lag_usd_total_market_cap_04            <dbl> 1.152833e+12, 1.182801e+12, 1.1…
#> $ lag_usd_total_market_cap_05            <dbl> 1.175627e+12, 1.152833e+12, 1.1…
#> $ lag_usd_total_market_cap_06            <dbl> 1.145641e+12, 1.175627e+12, 1.1…
#> $ lag_usd_total_market_cap_07            <dbl> 1.166254e+12, 1.145641e+12, 1.1…
#> $ lag_usd_total_market_cap_08            <dbl> 1.088592e+12, 1.166254e+12, 1.1…
#> $ lag_usd_total_market_cap_09            <dbl> 1.064655e+12, 1.088592e+12, 1.1…
#> $ lag_usd_total_market_cap_10            <dbl> 1.093184e+12, 1.064655e+12, 1.0…
#> $ lag_usd_total_market_cap_11            <dbl> 1.074730e+12, 1.093184e+12, 1.0…
#> $ lag_usd_total_market_cap_12            <dbl> 1.013838e+12, 1.074730e+12, 1.0…
#> $ lag_usd_total_market_cap_13            <dbl> 9.519674e+11, 1.013838e+12, 1.0…
#> $ lag_usd_total_market_cap_14            <dbl> 9.404086e+11, 9.519674e+11, 1.0…
#> $ lag_usd_total_volume_24h_04            <dbl> 77383433885, 67723817736, 69463…
#> $ lag_usd_total_volume_24h_05            <dbl> 65056772847, 77383433885, 67723…
#> $ lag_usd_total_volume_24h_06            <dbl> 68924084925, 65056772847, 77383…
#> $ lag_usd_total_volume_24h_07            <dbl> 84321789110, 68924084925, 65056…
#> $ lag_usd_total_volume_24h_08            <dbl> 62601200934, 84321789110, 68924…
#> $ lag_usd_total_volume_24h_09            <dbl> 83701408244, 62601200934, 84321…
#> $ lag_usd_total_volume_24h_10            <dbl> 101182591590, 83701408244, 6260…
#> $ lag_usd_total_volume_24h_11            <dbl> 97270664123, 101182591590, 8370…
#> $ lag_usd_total_volume_24h_12            <dbl> 64580463011, 97270664123, 10118…
#> $ lag_usd_total_volume_24h_13            <dbl> 91096944569, 64580463011, 97270…
#> $ lag_usd_total_volume_24h_14            <dbl> 76289657908, 91096944569, 64580…
#> $ lag_usd_total_volume_24h_reported_04   <dbl> 284152805501, 259934887339, 306…
#> $ lag_usd_total_volume_24h_reported_05   <dbl> 240552162883, 284152805501, 259…
#> $ lag_usd_total_volume_24h_reported_06   <dbl> 255638478619, 240552162883, 284…
#> $ lag_usd_total_volume_24h_reported_07   <dbl> 330280174188, 255638478619, 240…
#> $ lag_usd_total_volume_24h_reported_08   <dbl> 219779353230, 330280174188, 255…
#> $ lag_usd_total_volume_24h_reported_09   <dbl> 308441270560, 219779353230, 330…
#> $ lag_usd_total_volume_24h_reported_10   <dbl> 386858683239, 308441270560, 219…
#> $ lag_usd_total_volume_24h_reported_11   <dbl> 361232908236, 386858683239, 308…
#> $ lag_usd_total_volume_24h_reported_12   <dbl> 223240061246, 361232908236, 386…
#> $ lag_usd_total_volume_24h_reported_13   <dbl> 242876722809, 223240061246, 361…
#> $ lag_usd_total_volume_24h_reported_14   <dbl> 287084480406, 242876722809, 223…
#> $ lag_usd_altcoin_market_cap_04          <dbl> 616269148196, 638492553241, 617…
#> $ lag_usd_altcoin_market_cap_05          <dbl> 633827307898, 616269148196, 638…
#> $ lag_usd_altcoin_market_cap_06          <dbl> 624587523610, 633827307898, 616…
#> $ lag_usd_altcoin_market_cap_07          <dbl> 636180303279, 624587523610, 633…
#> $ lag_usd_altcoin_market_cap_08          <dbl> 604563947605, 636180303279, 624…
#> $ lag_usd_altcoin_market_cap_09          <dbl> 593770741356, 604563947605, 636…
#> $ lag_usd_altcoin_market_cap_10          <dbl> 614906573003, 593770741356, 604…
#> $ lag_usd_altcoin_market_cap_11          <dbl> 607271242970, 614906573003, 593…
#> $ lag_usd_altcoin_market_cap_12          <dbl> 585796442802, 607271242970, 614…
#> $ lag_usd_altcoin_market_cap_13          <dbl> 553500018991, 585796442802, 607…
#> $ lag_usd_altcoin_market_cap_14          <dbl> 550511824082, 553500018991, 585…
#> $ lag_usd_altcoin_volume_24h_04          <dbl> 32612622116, 31623104558, 36084…
#> $ lag_usd_altcoin_volume_24h_05          <dbl> 27284389880, 32612622116, 31623…
#> $ lag_usd_altcoin_volume_24h_06          <dbl> 33202888821, 27284389880, 32612…
#> $ lag_usd_altcoin_volume_24h_07          <dbl> 33565080485, 33202888821, 27284…
#> $ lag_usd_altcoin_volume_24h_08          <dbl> 28736551431, 33565080485, 33202…
#> $ lag_usd_altcoin_volume_24h_09          <dbl> 40037032687, 28736551431, 33565…
#> $ lag_usd_altcoin_volume_24h_10          <dbl> 46564591635, 40037032687, 28736…
#> $ lag_usd_altcoin_volume_24h_11          <dbl> 47811137109, 46564591635, 40037…
#> $ lag_usd_altcoin_volume_24h_12          <dbl> 35296250595, 47811137109, 46564…
#> $ lag_usd_altcoin_volume_24h_13          <dbl> 60918424794, 35296250595, 47811…
#> $ lag_usd_altcoin_volume_24h_14          <dbl> 36710003683, 60918424794, 35296…
#> $ lag_usd_altcoin_volume_24h_reported_04 <dbl> 133307012940, 143883048976, 151…
#> $ lag_usd_altcoin_volume_24h_reported_05 <dbl> 116269148253, 133307012940, 143…
#> $ lag_usd_altcoin_volume_24h_reported_06 <dbl> 138676737735, 116269148253, 133…
#> $ lag_usd_altcoin_volume_24h_reported_07 <dbl> 138765492138, 138676737735, 116…
#> $ lag_usd_altcoin_volume_24h_reported_08 <dbl> 110894992930, 138765492138, 138…
#> $ lag_usd_altcoin_volume_24h_reported_09 <dbl> 159653992121, 110894992930, 138…
#> $ lag_usd_altcoin_volume_24h_reported_10 <dbl> 182469531242, 159653992121, 110…
#> $ lag_usd_altcoin_volume_24h_reported_11 <dbl> 178537049213, 182469531242, 159…
#> $ lag_usd_altcoin_volume_24h_reported_12 <dbl> 121672058312, 178537049213, 182…
#> $ lag_usd_altcoin_volume_24h_reported_13 <dbl> 151040976226, 121672058312, 178…
#> $ lag_usd_altcoin_volume_24h_reported_14 <dbl> 151982926661, 151040976226, 121…

usemodels::use_glmnet(close ~ . , data=df_train)
#> glmnet_recipe <- 
#>   recipe(formula = close ~ ., data = df_train) %>% 
#>   step_zv(all_predictors()) %>% 
#>   step_normalize(all_numeric_predictors()) 
#> 
#> glmnet_spec <- 
#>   multinom_reg(penalty = tune(), mixture = tune()) %>% 
#>   set_mode("classification") %>% 
#>   set_engine("glmnet") 
#> 
#> glmnet_workflow <- 
#>   workflow() %>% 
#>   add_recipe(glmnet_recipe) %>% 
#>   add_model(glmnet_spec) 
#> 
#> glmnet_grid <- tidyr::crossing(penalty = 10^seq(-6, -1, length.out = 20), mixture = c(0.05, 
#>     0.2, 0.4, 0.6, 0.8, 1)) 
#> 
#> glmnet_tune <- 
#>   tune_grid(glmnet_workflow, resamples = stop("add your rsample object"), grid = glmnet_grid)

sessionInfo()
#> R version 4.3.3 (2024-02-29)
#> Platform: x86_64-pc-linux-gnu (64-bit)
#> Running under: Debian GNU/Linux 12 (bookworm)
#> 
#> Matrix products: default
#> BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.11.0 
#> LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.11.0
#> 
#> locale:
#>  [1] LC_CTYPE=en_GB.UTF-8       LC_NUMERIC=C              
#>  [3] LC_TIME=en_GB.UTF-8        LC_COLLATE=en_GB.UTF-8    
#>  [5] LC_MONETARY=en_GB.UTF-8    LC_MESSAGES=en_GB.UTF-8   
#>  [7] LC_PAPER=en_GB.UTF-8       LC_NAME=C                 
#>  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#> [11] LC_MEASUREMENT=en_GB.UTF-8 LC_IDENTIFICATION=C       
#> 
#> time zone: Europe/Brussels
#> tzcode source: system (glibc)
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> other attached packages:
#>  [1] usemodels_0.2.0    glmnet_4.1-8       Matrix_1.6-5       yardstick_1.3.0   
#>  [5] workflowsets_1.0.1 workflows_1.1.4    tune_1.1.2         tidyr_1.3.1       
#>  [9] tibble_3.2.1       rsample_1.2.0      recipes_1.0.10     purrr_1.0.2       
#> [13] parsnip_1.2.0      modeldata_1.3.0    infer_1.0.6        ggplot2_3.5.0     
#> [17] dplyr_1.1.4        dials_1.2.1        scales_1.3.0       broom_1.0.5       
#> [21] tidymodels_1.1.1  
#> 
#> loaded via a namespace (and not attached):
#>  [1] tidyselect_1.2.0    timeDate_4032.109   R.utils_2.12.3     
#>  [4] fastmap_1.1.1       reprex_2.1.0        digest_0.6.34      
#>  [7] rpart_4.1.23        timechange_0.3.0    lifecycle_1.0.4    
#> [10] survival_3.5-8      magrittr_2.0.3      compiler_4.3.3     
#> [13] rlang_1.1.3         tools_4.3.3         utf8_1.2.4         
#> [16] yaml_2.3.8          data.table_1.15.2   knitr_1.45         
#> [19] DiceDesign_1.10     R.cache_0.16.0      withr_3.0.0        
#> [22] R.oo_1.26.0         nnet_7.3-19         grid_4.3.3         
#> [25] fansi_1.0.6         colorspace_2.1-0    future_1.33.1      
#> [28] globals_0.16.2      iterators_1.0.14    MASS_7.3-60.0.1    
#> [31] cli_3.6.2           rmarkdown_2.25      generics_0.1.3     
#> [34] future.apply_1.11.1 splines_4.3.3       parallel_4.3.3     
#> [37] vctrs_0.6.5         hardhat_1.3.1       listenv_0.9.1      
#> [40] foreach_1.5.2       gower_1.0.1         glue_1.7.0         
#> [43] parallelly_1.37.1   codetools_0.2-19    shape_1.4.6.1      
#> [46] lubridate_1.9.3     gtable_0.3.4        munsell_0.5.0      
#> [49] GPfit_1.0-8         styler_1.10.2       pillar_1.9.0       
#> [52] furrr_0.3.1         htmltools_0.5.7     ipred_0.9-14       
#> [55] lava_1.7.3          R6_2.5.1            lhs_1.1.6          
#> [58] evaluate_0.23       lattice_0.22-5      R.methodsS3_1.8.2  
#> [61] backports_1.4.1     class_7.3-22        Rcpp_1.0.12        
#> [64] prodlim_2023.08.28  xfun_0.42           fs_1.6.3           
#> [67] pkgconfig_2.0.3

Created on 2024-03-06 with reprex v2.1.0

larry77 commented 8 months ago

I would like to add that this happens also with the (much simpler)

use_glmnet(body_mass_g ~ ., data = penguins)

Unlike what shown in the example here

https://usemodels.tidymodels.org/

larry77 commented 8 months ago

Any reaction on this? It actually affects every model in the package.

jrosell commented 1 month ago

Please @larry77, give a .csv as input instead. I can't reproduce your example (I use 0.2.0.9000 version)

library(tidymodels)
library(usemodels)
df_train <- tibble(
  close = c(71.37752, 72.92498),
  high = c(73.50968, 73.35770)
)
use_glmnet(close ~ ., data = df_train)
glmnet_recipe <- 
#   recipe(formula = close ~ ., data = df_train) %>% 
#   step_zv(all_predictors()) %>% 
#   step_normalize(all_numeric_predictors()) 

# glmnet_spec <- 
#   linear_reg(penalty = tune(), mixture = tune()) %>% 
#   set_mode("regression") %>% 
#   set_engine("glmnet") 

# glmnet_workflow <- 
#   workflow() %>% 
#   add_recipe(glmnet_recipe) %>% 
#   add_model(glmnet_spec) 

# glmnet_grid <- tidyr::crossing(penalty = 10^seq(-6, -1, length.out = 20), mixture = c(0.05, 
#     0.2, 0.4, 0.6, 0.8, 1)) 

# glmnet_tune <- 
#   tune_grid(glmnet_workflow, resamples = stop("add your rsample object"), grid = glmnet_grid) 
larry77 commented 1 month ago

Hi! Indeed I think I now understand the situation. Just refer to the palmerpenguin example at

https://usemodels.tidymodels.org/index.html

1) if I use the cran version of usemodels (0.2.0), then the issue I mentioned persists, i.e. a regression problem is handled as a classification problem. 2) with the development version of usemodels (the one with the same version number as you mention), everything works fine.

Apparently there is a bug in the cran package which has been fixed in the development version. It would have been nice to have a word from the developers during the > 6 months since I opened this issue.