r – Error in tune grid in elastic net regression in tidymodels

I’m trying to tune a regularized regression, but the tune grid command returns several errors. I tried several grids, several recipes, but even using only one predictor, it still returns an error.

Here’s a reproducible example

df <- tibble(normalized_losses = c(NA, NA, NA, 164, 164, NA, 
158, NA, 158, NA, 192, 192, 188, 188, NA, NA, NA, NA, 121, 98, 
81, 118, 118, 118, 148, 148, 148, 148, 110, 145, 137, 137, 101, 
101, 101, 110, 78, 106, 106, 85, 85, 85, 107, NA, NA, NA, NA, 
145, NA, NA, 104, 104, 104, 113, 113, 150, 150, 150, 150, 129, 
115, 129, 115, NA, 115, 118, NA, 93, 93, 93, 93, NA, 142, NA, 
NA, NA, 161, 161, 161, 161, 153, 153, NA, NA, NA, 125, 125, 125, 
137, 128, 128, 128, 122, 103, 128, 128, 122, 103, 168, 106, 106, 
128, 108, 108, 194, 194, 231, 161, 161, NA, NA, 161, 161, NA, 
NA, 161, 161, 161, 119, 119, 154, 154, 154, 74, NA, 186, NA, 
NA, NA, NA, NA, NA, 150, 104, 150, 104, 150, 104, 83, 83, 83, 
102, 102, 102, 102, 102, 89, 89, 85, 85, 87, 87, 74, 77, 81, 
91, 91, 91, 91, 91, 91, 91, 91, 168, 168, 168, 168, 134, 134, 
134, 134, 134, 134, 65, 65, 65, 65, 65, 197, 197, 90, NA, 122, 
122, 94, 94, 94, 94, 94, NA, 256, NA, NA, NA, 103, 74, 103, 74, 
103, 74, 95, 95, 95, 95, 95), Tipo_Cobustivel = c("gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "diesel", "gas", 
"gas", "diesel", "diesel", "diesel", "diesel", "diesel", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"diesel", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"diesel", "gas", "diesel", "gas", "diesel", "gas", "diesel", 
"gas", "diesel", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "diesel", "diesel", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "gas", "diesel", "gas", "gas", "gas", 
"gas", "gas", "gas", "gas", "diesel", "gas", "diesel", "gas", 
"gas", "diesel", "gas", "gas", "gas", "gas", "diesel", "gas", 
"gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", "gas", 
"diesel", "gas"), Tipo_Motor = c("std", "std", "std", "std", 
"std", "std", "std", "std", "turbo", "turbo", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "turbo", "std", "std", "std", "turbo", "std", "turbo", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "turbo", "turbo", "turbo", "turbo", "std", "std", "std", 
"std", "turbo", "std", "std", "std", "turbo", "turbo", "std", 
"turbo", "turbo", "turbo", "std", "std", "turbo", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "turbo", "std", "std", 
"turbo", "std", "turbo", "std", "turbo", "std", "turbo", "std", 
"turbo", "turbo", "std", "turbo", "std", "std", "std", "std", 
"turbo", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "turbo", "turbo", "std", "std", "std", "std", 
"std", "std", "std", "turbo", "std", "std", "std", "turbo", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"std", "std", "std", "std", "std", "turbo", "std", "std", "std", 
"std", "std", "std", "std", "std", "std", "std", "std", "std", 
"turbo", "std", "std", "std", "std", "turbo", "std", "std", "std", 
"std", "std", "turbo", "turbo", "std", "turbo", "std", "turbo", 
"turbo"), N_de_Portas = c("two", "two", "two", "four", "four", 
"two", "four", "four", "four", "two", "two", "four", "two", "four", 
"four", "four", "two", "four", "two", "two", "four", "two", "two", 
"two", "four", "four", "four", NA, "four", "two", "two", "two", 
"two", "two", "two", "four", "four", "two", "two", "four", "four", 
"four", "two", "four", "two", "four", "two", "four", "four", 
"two", "two", "two", "two", "four", "four", "two", "two", "two", 
"two", "two", "four", "two", "four", NA, "four", "four", "four", 
"four", "four", "two", "four", "four", "two", "four", "two", 
"two", "two", "two", "two", "two", "two", "two", "two", "two", 
"two", "four", "four", "four", "four", "two", "two", "two", "four", 
"four", "two", "two", "four", "four", "two", "four", "four", 
"four", "four", "four", "two", "two", "two", "four", "four", 
"four", "four", "four", "four", "four", "four", "four", "four", 
"four", "two", "two", "four", "four", "four", "four", "two", 
"two", "two", "two", "two", "two", "four", "two", "two", "four", 
"two", "four", "two", "four", "two", "two", "two", "four", "four", 
"four", "four", "four", "four", "four", "four", "four", "two", 
"two", "four", "four", "four", "four", "four", "four", "four", 
"four", "four", "four", "four", "two", "two", "two", "two", "two", 
"two", "two", "two", "two", "two", "four", "four", "four", "four", 
"four", "two", "two", "four", "four", "two", "two", "four", "four", 
"four", "four", "four", "two", "two", "four", "four", "four", 
"four", "four", "four", "four", "four", "four", "four", "four", 
"four", "four", "four"), Tracao = c("rwd", "rwd", "rwd", "fwd", 
"4wd", "fwd", "fwd", "fwd", "fwd", "4wd", "rwd", "rwd", "rwd", 
"rwd", "rwd", "rwd", "rwd", "rwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "rwd", "fwd", "fwd", "rwd", "rwd", "rwd", 
"rwd", "fwd", "fwd", "fwd", "fwd", "fwd", "rwd", "rwd", "rwd", 
"rwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "rwd", "rwd", 
"rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", 
"rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "fwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "4wd", "fwd", "fwd", "fwd", "4wd", "4wd", "fwd", "fwd", 
"4wd", "4wd", "fwd", "fwd", "fwd", "fwd", "4wd", "4wd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "rwd", "rwd", "rwd", 
"rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "rwd", "rwd", "rwd", "rwd", "fwd", "fwd", 
"fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", "fwd", 
"fwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", "rwd", 
"rwd", "rwd", "rwd"), base_da_roda = c(88.6, 88.6, 94.5, 99.8, 
99.4, 99.8, 105.8, 105.8, 105.8, 99.5, 101.2, 101.2, 101.2, 101.2, 
103.5, 103.5, 103.5, 110, 88.4, 94.5, 94.5, 93.7, 93.7, 93.7, 
93.7, 93.7, 93.7, 93.7, 103.3, 95.9, 86.6, 86.6, 93.7, 93.7, 
93.7, 96.5, 96.5, 96.5, 96.5, 96.5, 96.5, 96.5, 96.5, 94.3, 94.5, 
94.5, 96, 113, 113, 102, 93.1, 93.1, 93.1, 93.1, 93.1, 95.3, 
95.3, 95.3, 95.3, 98.8, 98.8, 98.8, 98.8, 98.8, 98.8, 104.9, 
104.9, 110, 110, 106.7, 115.6, 115.6, 96.6, 120.9, 112, 102.7, 
93.7, 93.7, 93.7, 93, 96.3, 96.3, 95.9, 95.9, 95.9, 96.3, 96.3, 
96.3, 96.3, 94.5, 94.5, 94.5, 94.5, 94.5, 94.5, 94.5, 94.5, 94.5, 
95.1, 97.2, 97.2, 100.4, 100.4, 100.4, 91.3, 91.3, 99.2, 107.9, 
107.9, 114.2, 114.2, 107.9, 107.9, 114.2, 114.2, 107.9, 107.9, 
108, 93.7, 93.7, 93.7, 93.7, 93.7, 103.3, 95.9, 94.5, 89.5, 89.5, 
89.5, 98.4, 96.1, 96.1, 99.1, 99.1, 99.1, 99.1, 99.1, 99.1, 93.7, 
93.7, 93.3, 97.2, 97.2, 97.2, 97, 97, 97, 97, 96.9, 96.9, 95.7, 
95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 95.7, 
95.7, 94.5, 94.5, 94.5, 94.5, 98.4, 98.4, 98.4, 98.4, 98.4, 98.4, 
102.4, 102.4, 102.4, 102.4, 102.4, 102.9, 102.9, 104.5, 104.5, 
97.3, 97.3, 97.3, 97.3, 97.3, 97.3, 97.3, 94.5, 94.5, 100.4, 
100.4, 100.4, 104.3, 104.3, 104.3, 104.3, 104.3, 104.3, 109.1, 
109.1, 109.1, 109.1, 109.1), Comprimento = c(168.8, 168.8, 171.2, 
176.6, 176.6, 177.3, 192.7, 192.7, 192.7, 178.2, 176.8, 176.8, 
176.8, 176.8, 189, 189, 193.8, 197, 141.1, 155.9, 158.8, 157.3, 
157.3, 157.3, 157.3, 157.3, 157.3, 157.3, 174.6, 173.2, 144.6, 
144.6, 150, 150, 150, 163.4, 157.1, 167.5, 167.5, 175.4, 175.4, 
175.4, 169.1, 170.7, 155.9, 155.9, 172.6, 199.6, 199.6, 191.7, 
159.1, 159.1, 159.1, 166.8, 166.8, 169, 169, 169, 169, 177.8, 
177.8, 177.8, 177.8, 177.8, 177.8, 175, 175, 190.9, 190.9, 187.5, 
202.6, 202.6, 180.3, 208.1, 199.2, 178.4, 157.3, 157.3, 157.3, 
157.3, 173, 173, 173.2, 173.2, 173.2, 172.4, 172.4, 172.4, 172.4, 
165.3, 165.3, 165.3, 165.3, 170.2, 165.3, 165.6, 165.3, 170.2, 
162.4, 173.4, 173.4, 181.7, 184.6, 184.6, 170.7, 170.7, 178.5, 
186.7, 186.7, 198.9, 198.9, 186.7, 186.7, 198.9, 198.9, 186.7, 
186.7, 186.7, 157.3, 157.3, 157.3, 167.3, 167.3, 174.6, 173.2, 
168.9, 168.9, 168.9, 168.9, 175.7, 181.5, 176.8, 186.6, 186.6, 
186.6, 186.6, 186.6, 186.6, 156.9, 157.9, 157.3, 172, 172, 172, 
172, 172, 173.5, 173.5, 173.6, 173.6, 158.7, 158.7, 158.7, 169.7, 
169.7, 169.7, 166.3, 166.3, 166.3, 166.3, 166.3, 166.3, 166.3, 
168.7, 168.7, 168.7, 168.7, 176.2, 176.2, 176.2, 176.2, 176.2, 
176.2, 175.6, 175.6, 175.6, 175.6, 175.6, 183.5, 183.5, 187.8, 
187.8, 171.7, 171.7, 171.7, 171.7, 171.7, 171.7, 171.7, 159.3, 
165.7, 180.2, 180.2, 183.1, 188.8, 188.8, 188.8, 188.8, 188.8, 
188.8, 188.8, 188.8, 188.8, 188.8, 188.8), Largura = c(64.1, 
64.1, 65.5, 66.2, 66.4, 66.3, 71.4, 71.4, 71.4, 67.9, 64.8, 64.8, 
64.8, 64.8, 66.9, 66.9, 67.9, 70.9, 60.3, 63.6, 63.6, 63.8, 63.8, 
63.8, 63.8, 63.8, 63.8, 63.8, 64.6, 66.3, 63.9, 63.9, 64, 64, 
64, 64, 63.9, 65.2, 65.2, 65.2, 62.5, 65.2, 66, 61.8, 63.6, 63.6, 
65.2, 69.6, 69.6, 70.6, 64.2, 64.2, 64.2, 64.2, 64.2, 65.7, 65.7, 
65.7, 65.7, 66.5, 66.5, 66.5, 66.5, 66.5, 66.5, 66.1, 66.1, 70.3, 
70.3, 70.3, 71.7, 71.7, 70.5, 71.7, 72, 68, 64.4, 64.4, 64.4, 
63.8, 65.4, 65.4, 66.3, 66.3, 66.3, 65.4, 65.4, 65.4, 65.4, 63.8, 
63.8, 63.8, 63.8, 63.8, 63.8, 63.8, 63.8, 63.8, 63.8, 65.2, 65.2, 
66.5, 66.5, 66.5, 67.9, 67.9, 67.9, 68.4, 68.4, 68.4, 68.4, 68.4, 
68.4, 68.4, 68.4, 68.4, 68.4, 68.3, 63.8, 63.8, 63.8, 63.8, 63.8, 
64.6, 66.3, 68.3, 65, 65, 65, 72.3, 66.5, 66.6, 66.5, 66.5, 66.5, 
66.5, 66.5, 66.5, 63.4, 63.6, 63.8, 65.4, 65.4, 65.4, 65.4, 65.4, 
65.4, 65.4, 65.4, 65.4, 63.6, 63.6, 63.6, 63.6, 63.6, 63.6, 64.4, 
64.4, 64.4, 64.4, 64.4, 64.4, 64.4, 64, 64, 64, 64, 65.6, 65.6, 
65.6, 65.6, 65.6, 65.6, 66.5, 66.5, 66.5, 66.5, 66.5, 67.7, 67.7, 
66.5, 66.5, 65.5, 65.5, 65.5, 65.5, 65.5, 65.5, 65.5, 64.2, 64, 
66.9, 66.9, 66.9, 67.2, 67.2, 67.2, 67.2, 67.2, 67.2, 68.9, 68.8, 
68.9, 68.9, 68.9), Altura = c(48.8, 48.8, 52.4, 54.3, 54.3, 53.1, 
55.7, 55.7, 55.9, 52, 54.3, 54.3, 54.3, 54.3, 55.7, 55.7, 53.7, 
56.3, 53.2, 52, 52, 50.8, 50.8, 50.8, 50.6, 50.6, 50.6, 50.6, 
59.8, 50.2, 50.8, 50.8, 52.6, 52.6, 52.6, 54.5, 58.3, 53.3, 53.3, 
54.1, 54.1, 54.1, 51, 53.5, 52, 52, 51.4, 52.8, 52.8, 47.8, 54.1, 
54.1, 54.1, 54.1, 54.1, 49.6, 49.6, 49.6, 49.6, 53.7, 55.5, 53.7, 
55.5, 55.5, 55.5, 54.4, 54.4, 56.5, 58.7, 54.9, 56.3, 56.5, 50.8, 
56.7, 55.4, 54.8, 50.8, 50.8, 50.8, 50.8, 49.4, 49.4, 50.2, 50.2, 
50.2, 51.6, 51.6, 51.6, 51.6, 54.5, 54.5, 54.5, 54.5, 53.5, 54.5, 
53.3, 54.5, 53.5, 53.3, 54.7, 54.7, 55.1, 56.1, 55.1, 49.7, 49.7, 
49.7, 56.7, 56.7, 58.7, 58.7, 56.7, 56.7, 56.7, 58.7, 56.7, 56.7, 
56, 50.8, 50.8, 50.6, 50.8, 50.8, 59.8, 50.2, 50.2, 51.6, 51.6, 
51.6, 50.5, 55.2, 50.5, 56.1, 56.1, 56.1, 56.1, 56.1, 56.1, 53.7, 
53.7, 55.7, 52.5, 52.5, 52.5, 54.3, 54.3, 53, 53, 54.9, 54.9, 
54.5, 54.5, 54.5, 59.1, 59.1, 59.1, 53, 52.8, 53, 52.8, 53, 52.8, 
52.8, 52.6, 52.6, 52.6, 52.6, 52, 52, 52, 52, 52, 53, 54.9, 54.9, 
53.9, 54.9, 53.9, 52, 52, 54.1, 54.1, 55.7, 55.7, 55.7, 55.7, 
55.7, 55.7, 55.7, 55.6, 51.4, 55.1, 55.1, 55.1, 56.2, 57.5, 56.2, 
57.5, 56.2, 57.5, 55.5, 55.5, 55.5, 55.5, 55.5), Peso_do_Carburador = c(2548, 
2548, 2823, 2337, 2824, 2507, 2844, 2954, 3086, 3053, 2395, 2395, 
2710, 2765, 3055, 3230, 3380, 3505, 1488, 1874, 1909, 1876, 1876, 
2128, 1967, 1989, 1989, 2191, 2535, 2811, 1713, 1819, 1837, 1940, 
1956, 2010, 2024, 2236, 2289, 2304, 2372, 2465, 2293, 2337, 1874, 
1909, 2734, 4066, 4066, 3950, 1890, 1900, 1905, 1945, 1950, 2380, 
2380, 2385, 2500, 2385, 2410, 2385, 2410, 2443, 2425, 2670, 2700, 
3515, 3750, 3495, 3770, 3740, 3685, 3900, 3715, 2910, 1918, 1944, 
2004, 2145, 2370, 2328, 2833, 2921, 2926, 2365, 2405, 2403, 2403, 
1889, 2017, 1918, 1938, 2024, 1951, 2028, 1971, 2037, 2008, 2324, 
2302, 3095, 3296, 3060, 3071, 3139, 3139, 3020, 3197, 3230, 3430, 
3075, 3252, 3285, 3485, 3075, 3252, 3130, 1918, 2128, 1967, 1989, 
2191, 2535, 2818, 2778, 2756, 2756, 2800, 3366, 2579, 2460, 2658, 
2695, 2707, 2758, 2808, 2847, 2050, 2120, 2240, 2145, 2190, 2340, 
2385, 2510, 2290, 2455, 2420, 2650, 1985, 2040, 2015, 2280, 2290, 
3110, 2081, 2109, 2275, 2275, 2094, 2122, 2140, 2169, 2204, 2265, 
2300, 2540, 2536, 2551, 2679, 2714, 2975, 2326, 2480, 2414, 2414, 
2458, 2976, 3016, 3131, 3151, 2261, 2209, 2264, 2212, 2275, 2319, 
2300, 2254, 2221, 2661, 2579, 2563, 2912, 3034, 2935, 3042, 3045, 
3157, 2952, 3049, 3012, 3217, 3062), tamanho_do_motor = c(130, 
130, 152, 109, 136, 136, 136, 136, 131, 131, 108, 108, 164, 164, 
164, 209, 209, 209, 61, 90, 90, 90, 90, 98, 90, 90, 90, 98, 122, 
156, 92, 92, 79, 92, 92, 92, 92, 110, 110, 110, 110, 110, 110, 
111, 90, 90, 119, 258, 258, 326, 91, 91, 91, 91, 91, 70, 70, 
70, 80, 122, 122, 122, 122, 122, 122, 140, 134, 183, 183, 183, 
183, 234, 234, 308, 304, 140, 92, 92, 92, 98, 110, 122, 156, 
156, 156, 122, 122, 110, 110, 97, 103, 97, 97, 97, 97, 97, 97, 
97, 97, 120, 120, 181, 181, 181, 181, 181, 181, 120, 152, 120, 
152, 120, 152, 120, 152, 120, 152, 134, 90, 98, 90, 90, 98, 122, 
156, 151, 194, 194, 194, 203, 132, 132, 121, 121, 121, 121, 121, 
121, 97, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 108, 
92, 92, 92, 92, 92, 92, 98, 98, 110, 110, 98, 98, 98, 98, 98, 
98, 98, 146, 146, 146, 146, 146, 146, 122, 110, 122, 122, 122, 
171, 171, 171, 161, 97, 109, 97, 109, 109, 97, 109, 109, 109, 
136, 97, 109, 141, 141, 141, 141, 130, 130, 141, 141, 173, 145, 
141), Calibre_dos_pneus = c(3.47, 3.47, 2.68, 3.19, 3.19, 3.19, 
3.19, 3.19, 3.13, 3.13, 3.5, 3.5, 3.31, 3.31, 3.31, 3.62, 3.62, 
3.62, 2.91, 3.03, 3.03, 2.97, 2.97, 3.03, 2.97, 2.97, 2.97, 3.03, 
3.34, 3.6, 2.91, 2.91, 2.91, 2.91, 2.91, 2.91, 2.92, 3.15, 3.15, 
3.15, 3.15, 3.15, 3.15, 3.31, 3.03, 3.03, 3.43, 3.63, 3.63, 3.54, 
3.03, 3.03, 3.03, 3.03, 3.08, NA, NA, NA, NA, 3.39, 3.39, 3.39, 
3.39, 3.39, 3.39, 3.76, 3.43, 3.58, 3.58, 3.58, 3.58, 3.46, 3.46, 
3.8, 3.8, 3.78, 2.97, 2.97, 2.97, 3.03, 3.17, 3.35, 3.58, 3.59, 
3.59, 3.35, 3.35, 3.17, 3.17, 3.15, 2.99, 3.15, 3.15, 3.15, 3.15, 
3.15, 3.15, 3.15, 3.15, 3.33, 3.33, 3.43, 3.43, 3.43, 3.43, 3.43, 
3.43, 3.46, 3.7, 3.46, 3.7, 3.46, 3.7, 3.46, 3.7, 3.46, 3.7, 
3.61, 2.97, 3.03, 2.97, 2.97, 2.97, 3.35, 3.59, 3.94, 3.74, 3.74, 
3.74, 3.94, 3.46, 3.46, 3.54, 3.54, 2.54, 3.54, 3.54, 3.54, 3.62, 
3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 3.62, 
3.05, 3.05, 3.05, 3.05, 3.05, 3.05, 3.19, 3.19, 3.27, 3.27, 3.19, 
3.19, 3.19, 3.19, 3.19, 3.24, 3.24, 3.62, 3.62, 3.62, 3.62, 3.62, 
3.62, 3.31, 3.27, 3.31, 3.31, 3.31, 3.27, 3.27, 3.27, 3.27, 3.01, 
3.19, 3.01, 3.19, 3.19, 3.01, 3.19, 3.19, 3.19, 3.19, 3.01, 3.19, 
3.78, 3.78, 3.78, 3.78, 3.62, 3.62, 3.78, 3.78, 3.58, 3.01, 3.78
), Derrame = c(2.68, 2.68, 3.47, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 
3.4, 2.8, 2.8, 3.19, 3.19, 3.19, 3.39, 3.39, 3.39, 3.03, 3.11, 
3.11, 3.23, 3.23, 3.39, 3.23, 3.23, 3.23, 3.39, 3.46, 3.9, 3.41, 
3.41, 3.07, 3.41, 3.41, 3.41, 3.41, 3.58, 3.58, 3.58, 3.58, 3.58, 
3.58, 3.23, 3.11, 3.11, 3.23, 4.17, 4.17, 2.76, 3.15, 3.15, 3.15, 
3.15, 3.15, NA, NA, NA, NA, 3.39, 3.39, 3.39, 3.39, 3.39, 3.39, 
3.16, 3.64, 3.64, 3.64, 3.64, 3.64, 3.1, 3.1, 3.35, 3.35, 3.12, 
3.23, 3.23, 3.23, 3.39, 3.46, 3.46, 3.86, 3.86, 3.86, 3.46, 3.46, 
3.46, 3.46, 3.29, 3.47, 3.29, 3.29, 3.29, 3.29, 3.29, 3.29, 3.29, 
3.29, 3.47, 3.47, 3.27, 3.27, 3.27, 3.27, 3.27, 3.27, 3.19, 3.52, 
3.19, 3.52, 2.19, 3.52, 2.19, 3.52, 3.19, 3.52, 3.21, 3.23, 3.39, 
3.23, 3.23, 3.23, 3.46, 3.86, 3.11, 2.9, 2.9, 2.9, 3.11, 3.9, 
3.9, 3.07, 3.07, 2.07, 3.07, 3.07, 3.07, 2.36, 2.64, 2.64, 2.64, 
2.64, 2.64, 2.64, 2.64, 2.64, 2.64, 2.64, 2.64, 3.03, 3.03, 3.03, 
3.03, 3.03, 3.03, 3.03, 3.03, 3.35, 3.35, 3.03, 3.03, 3.03, 3.03, 
3.03, 3.08, 3.08, 3.5, 3.5, 3.5, 3.5, 3.5, 3.5, 3.54, 3.35, 3.54, 
3.54, 3.54, 3.35, 3.35, 3.35, 3.35, 3.4, 3.4, 3.4, 3.4, 3.4, 
3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.4, 3.15, 3.15, 3.15, 3.15, 3.15, 
3.15, 3.15, 3.15, 2.87, 3.4, 3.15), Taxa_de_Compressao = c(9, 
9, 9, 10, 8, 8.5, 8.5, 8.5, 8.3, 7, 8.8, 8.8, 9, 9, 9, 8, 8, 
8, 9.5, 9.6, 9.6, 9.41, 9.4, 7.6, 9.4, 9.4, 9.4, 7.6, 8.5, 7, 
9.6, 9.2, 10.1, 9.2, 9.2, 9.2, 9.2, 9, 9, 9, 9, 9, 9.1, 8.5, 
9.6, 9.6, 9.2, 8.1, 8.1, 11.5, 9, 9, 9, 9, 9, 9.4, 9.4, 9.4, 
9.4, 8.6, 8.6, 8.6, 8.6, 22.7, 8.6, 8, 22, 21.5, 21.5, 21.5, 
21.5, 8.3, 8.3, 8, 8, 8, 9.4, 9.4, 9.4, 7.6, 7.5, 8.5, 7, 7, 
7, 8.5, 8.5, 7.5, 7.5, 9.4, 21.9, 9.4, 9.4, 9.4, 9.4, 9.4, 9.4, 
9.4, 9.4, 8.5, 8.5, 9, 9, 9, 9, 7.8, 9, 8.4, 21, 8.4, 21, 8.4, 
21, 8.4, 21, 8.4, 21, 7, 9.4, 7.6, 9.4, 9.4, 9.4, 8.5, 7, 9.5, 
9.5, 9.5, 9.5, 10, 8.7, 8.7, 9.31, 9.3, 9.3, 9.3, 9, 9, 9, 8.7, 
8.7, 9.5, 9.5, 9, 9, 7.7, 9, 9, 9, 7.7, 9, 9, 9, 9, 9, 9, 9, 
9, 22.5, 22.5, 9, 9, 9, 9, 9, 9.4, 9.4, 9.3, 9.3, 9.3, 9.3, 9.3, 
9.3, 8.7, 22.5, 8.7, 8.7, 8.7, 9.3, 9.3, 9.2, 9.2, 23, 9, 23, 
9, 9, 23, 10, 8.5, 8.5, 8.5, 23, 9, 9.5, 9.5, 9.5, 9.5, 7.5, 
7.5, 9.5, 8.7, 8.8, 23, 9.5), Cavalos = c(111, 111, 154, 102, 
115, 110, 110, 110, 140, 160, 101, 101, 121, 121, 121, 182, 182, 
182, 48, 70, 70, 68, 68, 102, 68, 68, 68, 102, 88, 145, 58, 76, 
60, 76, 76, 76, 76, 86, 86, 86, 86, 101, 100, 78, 70, 70, 90, 
176, 176, 262, 68, 68, 68, 68, 68, 101, 101, 101, 135, 84, 84, 
84, 84, 64, 84, 120, 72, 123, 123, 123, 123, 155, 155, 184, 184, 
175, 68, 68, 68, 102, 116, 88, 145, 145, 145, 88, 88, 116, 116, 
69, 55, 69, 69, 69, 69, 69, 69, 69, 69, 97, 97, 152, 152, 152, 
160, 200, 160, 97, 95, 97, 95, 95, 95, 95, 95, 97, 95, 142, 68, 
102, 68, 68, 68, 88, 145, 143, 207, 207, 207, 288, NA, NA, 110, 
110, 110, 110, 160, 160, 69, 73, 73, 82, 82, 94, 82, 111, 82, 
94, 82, 111, 62, 62, 62, 62, 62, 62, 70, 70, 56, 56, 70, 70, 
70, 70, 70, 112, 112, 116, 116, 116, 116, 116, 116, 92, 73, 92, 
92, 92, 161, 161, 156, 156, 52, 85, 52, 85, 85, 68, 100, 90, 
90, 110, 68, 88, 114, 114, 114, 114, 162, 162, 114, 160, 134, 
106, 114), rpm_maximo = c(5000, 5000, 5000, 5500, 5500, 5500, 
5500, 5500, 5500, 5500, 5800, 5800, 4250, 4250, 4250, 5400, 5400, 
5400, 5100, 5400, 5400, 5500, 5500, 5500, 5500, 5500, 5500, 5500, 
5000, 5000, 4800, 6000, 5500, 6000, 6000, 6000, 6000, 5800, 5800, 
5800, 5800, 5800, 5500, 4800, 5400, 5400, 5000, 4750, 4750, 5000, 
5000, 5000, 5000, 5000, 5000, 6000, 6000, 6000, 6000, 4800, 4800, 
4800, 4800, 4650, 4800, 5000, 4200, 4350, 4350, 4350, 4350, 4750, 
4750, 4500, 4500, 5000, 5500, 5500, 5500, 5500, 5500, 5000, 5000, 
5000, 5000, 5000, 5000, 5500, 5500, 5200, 4800, 5200, 5200, 5200, 
5200, 5200, 5200, 5200, 5200, 5200, 5200, 5200, 5200, 5200, 5200, 
5200, 5200, 5000, 4150, 5000, 4150, 5000, 4150, 5000, 4150, 5000, 
4150, 5600, 5500, 5500, 5500, 5500, 5500, 5000, 5000, 5500, 5900, 
5900, 5900, 5750, NA, NA, 5250, 5250, 5250, 5250, 5500, 5500, 
4900, 4400, 4400, 4800, 4400, 5200, 4800, 4800, 4800, 5200, 4800, 
4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4800, 4500, 4500, 
4800, 4800, 4800, 4800, 4800, 6600, 6600, 4800, 4800, 4800, 4800, 
4800, 4800, 4200, 4500, 4200, 4200, 4200, 5200, 5200, 5200, 5200, 
4800, 5250, 4800, 5250, 5250, 4500, 5500, 5500, 5500, 5500, 4500, 
5500, 5400, 5400, 5400, 5400, 5100, 5100, 5400, 5300, 5500, 4800, 
5400), city_mpg = c(21, 21, 19, 24, 18, 19, 19, 19, 17, 16, 23, 
23, 21, 21, 20, 16, 16, 15, 47, 38, 38, 37, 31, 24, 31, 31, 31, 
24, 24, 19, 49, 31, 38, 30, 30, 30, 30, 27, 27, 27, 27, 24, 25, 
24, 38, 38, 24, 15, 15, 13, 30, 31, 31, 31, 31, 17, 17, 17, 16, 
26, 26, 26, 26, 36, 26, 19, 31, 22, 22, 22, 22, 16, 16, 14, 14, 
19, 37, 31, 31, 24, 23, 25, 19, 19, 19, 25, 25, 23, 23, 31, 45, 
31, 31, 31, 31, 31, 31, 31, 31, 27, 27, 17, 17, 19, 19, 17, 19, 
19, 28, 19, 25, 19, 28, 19, 25, 19, 28, 18, 37, 24, 31, 31, 31, 
24, 19, 19, 17, 17, 17, 17, 23, 23, 21, 21, 21, 21, 19, 19, 31, 
26, 26, 32, 28, 26, 24, 24, 28, 25, 23, 23, 35, 31, 31, 31, 27, 
27, 30, 30, 34, 38, 38, 28, 28, 29, 29, 26, 26, 24, 24, 24, 24, 
24, 24, 29, 30, 27, 27, 27, 20, 19, 20, 19, 37, 27, 37, 27, 27, 
37, 26, 24, 24, 19, 33, 25, 23, 23, 24, 24, 17, 17, 23, 19, 18, 
26, 19), highway_mpg = c(27, 27, 26, 30, 22, 25, 25, 25, 20, 
22, 29, 29, 28, 28, 25, 22, 22, 20, 53, 43, 43, 41, 38, 30, 38, 
38, 38, 30, 30, 24, 54, 38, 42, 34, 34, 34, 34, 33, 33, 33, 33, 
28, 31, 29, 43, 43, 29, 19, 19, 17, 31, 38, 38, 38, 38, 23, 23, 
23, 23, 32, 32, 32, 32, 42, 32, 27, 39, 25, 25, 25, 25, 18, 18, 
16, 16, 24, 41, 38, 38, 30, 30, 32, 24, 24, 24, 32, 32, 30, 30, 
37, 50, 37, 37, 37, 37, 37, 37, 37, 37, 34, 34, 22, 22, 25, 25, 
23, 25, 24, 33, 24, 25, 24, 33, 24, 25, 24, 33, 24, 41, 30, 38, 
38, 38, 30, 24, 27, 25, 25, 25, 28, 31, 31, 28, 28, 28, 28, 26, 
26, 36, 31, 31, 37, 33, 32, 25, 29, 32, 31, 29, 23, 39, 38, 38, 
37, 32, 32, 37, 37, 36, 47, 47, 34, 34, 34, 34, 29, 29, 30, 30, 
30, 30, 30, 30, 34, 33, 32, 32, 32, 24, 24, 24, 24, 46, 34, 46, 
34, 34, 42, 32, 29, 29, 24, 38, 31, 28, 28, 28, 28, 22, 22, 28, 
25, 23, 27, 25), Preco = c(13495, 16500, 16500, 13950, 17450, 
        15250, 17710, 18920, 23875, NA, 16430, 16925, 20970, 21105, 24565, 
        30760, 41315, 36880, 5151, 6295, 6575, 5572, 6377, 7957, 6229, 
        6692, 7609, 8558, 8921, 12964, 6479, 6855, 5399, 6529, 7129, 
        7295, 7295, 7895, 9095, 8845, 10295, 12945, 10345, 6785, NA, 
        NA, 11048, 32250, 35550, 36000, 5195, 6095, 6795, 6695, 7395, 
        10945, 11845, 13645, 15645, 8845, 8495, 10595, 10245, 10795, 
        11245, 18280, 18344, 25552, 28248, 28176, 31600, 34184, 35056, 
        40960, 45400, 16503, 5389, 6189, 6669, 7689, 9959, 8499, 12629, 
        14869, 14489, 6989, 8189, 9279, 9279, 5499, 7099, 6649, 6849, 
        7349, 7299, 7799, 7499, 7999, 8249, 8949, 9549, 13499, 14399, 
        13499, 17199, 19699, 18399, 11900, 13200, 12440, 13860, 15580, 
        16900, 16695, 17075, 16630, 17950, 18150, 5572, 7957, 6229, 6692, 
        7609, 8921, 12764, 22018, 32528, 34028, 37028, NA, 9295, 9895, 
        11850, 12170, 15040, 15510, 18150, 18620, 5118, 7053, 7603, 7126, 
        7775, 9960, 9233, 11259, 7463, 10198, 8013, 11694, 5348, 6338, 
        6488, 6918, 7898, 8778, 6938, 7198, 7898, 7788, 7738, 8358, 9258, 
        8058, 8238, 9298, 9538, 8449, 9639, 9989, 11199, 11549, 17669, 
        8948, 10698, 9988, 10898, 11248, 16558, 15998, 15690, 15750, 
7775, 7975, 7995, 8195, 8495, 9495, 9995, 11595, 9980, 13295, 
13845, 12290, 12940, 13415, 15985, 16515, 18420, 18950, 16845, 
19045, 21485, 22470, 22625))


split <- initial_split(df, prop = .8, strata = Preco)

df_treino <- training(split)
df_teste <- testing(split)


######### Receita #################
receita1 <- recipe(Preco ~ Largura, data = df_treino) %>%
       step_naomit() 
  

lm_model_lasso <- linear_reg() %>%
  
  set_engine('glmnet') %>%
  
  set_args(penalty = tune(),
           mixture =  tune()
  )


lm_lasso_workflow <- workflow() %>%
  add_model(lm_model_lasso) %>%
  add_recipe(receita1)

########## Definindo grade de busca ###############

lm_grid <- grid_latin_hypercube(penalty(), 
                                mixture(), size = 30)

######## Tunando o modelo #################
bts <- bootstraps(df_treino,times = 5,strata = Preco)


lm_tune <-tune_grid(lm_lasso_workflow,
                    resamples = bts,
                    grid =  lm_grid)

My sessionInfo:

> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19043)

Matrix products: default

locale:
[1] LC_COLLATE=Portuguese_Brazil.utf8  LC_CTYPE=Portuguese_Brazil.utf8   
[3] LC_MONETARY=Portuguese_Brazil.utf8 LC_NUMERIC=C                      
[5] LC_TIME=Portuguese_Brazil.utf8    

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

other attached packages:
 [1] MLDataR_0.1.3      pacman_0.5.1       ranger_0.13.1     
 [4] glmnet_4.1-4       Matrix_1.4-1       vip_0.3.2         
 [7] DataExplorer_0.8.2 readxl_1.4.0       yardstick_1.0.0   
[10] workflowsets_0.2.1 workflows_0.2.6    tune_0.2.0        
[13] tidyr_1.2.0        tibble_3.1.7       rsample_0.1.1     
[16] recipes_0.2.0      purrr_0.3.4        parsnip_0.2.1     
[19] modeldata_0.1.1    infer_1.0.0        ggplot2_3.3.6     
[22] dplyr_1.0.9        dials_0.1.1        scales_1.2.0      
[25] broom_0.8.0        tidymodels_0.2.0  

loaded via a namespace (and not attached):
 [1] splines_4.2.0       foreach_1.5.2       warp_0.2.0         
 [4] prodlim_2019.11.13  BiocManager_1.30.18 GPfit_1.0-8        
 [7] cellranger_1.1.0    globals_0.15.0      ipred_0.9-13       
[10] pillar_1.7.0        backports_1.4.1     lattice_0.20-45    
[13] glue_1.6.2          digest_0.6.29       hardhat_1.0.0      
[16] colorspace_2.0-3    htmltools_0.5.2     timeDate_3043.102  
[19] pkgconfig_2.0.3     lhs_1.1.5           DiceDesign_1.9     
[22] listenv_0.8.0       slider_0.2.2        gower_1.0.0        
[25] lava_1.6.10         farver_2.1.0        generics_0.1.2     
[28] ellipsis_0.3.2      withr_2.5.0         furrr_0.3.0        
[31] nnet_7.3-17         cli_3.3.0           survival_3.3-1     
[34] magrittr_2.0.3      crayon_1.5.1        evaluate_0.15      
[37] future_1.26.1       fansi_1.0.3         parallelly_1.31.1  
[40] MASS_7.3-56         class_7.3-20        tools_4.2.0        
[43] data.table_1.14.2   lifecycle_1.0.1     munsell_0.5.0      
[46] networkD3_0.4       compiler_4.2.0      rlang_1.0.2        
[49] grid_4.2.0          iterators_1.0.14    rstudioapi_0.13    
[52] htmlwidgets_1.5.4   igraph_1.3.1        labeling_0.4.2     
[55] rmarkdown_2.14      gtable_0.3.0        codetools_0.2-18   
[58] R6_2.5.1            gridExtra_2.3       lubridate_1.8.0    
[61] knitr_1.39          fastmap_1.1.0       future.apply_1.9.0 
[64] utf8_1.2.2          shape_1.4.6         Rcpp_1.0.8.3       
[67] vctrs_0.4.1         rpart_4.1.16        tidyselect_1.1.2   
[70] xfun_0.31 

Can anyone help me with this issue? After a lot of trying around here, I gave up.

Leave a Comment