Stuck in replication example in Chapter 7
melyale opened this issue · comments
Hello, I am trying to replicate the first classification example in Chapter 7 but I receive an error.
I am trying to run this code
nb_fit <- complaint_wf %>%
add_model(nb_spec) %>%
fit(data = complaints_train)
But I am receiving the following error
Error in app$vspace(new_style$margin-top
%||% 0) :
attempt to apply non-function
Do you have an idea what can be happening? I am stuck in this part.
Thanks in advance for your help!
Hello @melyale! I'm sorry to hear you are running into issues.
Can you run the following code for me and tell me what you get? If you can make a reprex that would be great. If you've never heard of a reprex before, start by reading "What is a reprex", and follow the advice further down that page.
library(tidyverse)
library(tidymodels)
library(textrecipes)
library(discrim)
complaints <- read_csv("https://raw.githubusercontent.com/emilhvitfeldt/smltar/master/data/complaints.csv.gz")
set.seed(1234)
complaints2class <- complaints %>%
mutate(product = factor(if_else(
product == paste("Credit reporting, credit repair services,",
"or other personal consumer reports"),
"Credit", "Other"
)))
complaints_split <- initial_split(complaints2class, strata = product)
complaints_train <- training(complaints_split)
complaints_test <- testing(complaints_split)
complaints_rec <-
recipe(product ~ consumer_complaint_narrative, data = complaints_train)
complaints_rec <- complaints_rec %>%
step_tokenize(consumer_complaint_narrative) %>%
step_tokenfilter(consumer_complaint_narrative, max_tokens = 1e3) %>%
step_tfidf(consumer_complaint_narrative)
complaint_wf <- workflow() %>%
add_recipe(complaints_rec)
nb_spec <- naive_Bayes() %>%
set_mode("classification") %>%
set_engine("naivebayes")
nb_fit <- complaint_wf %>%
add_model(nb_spec) %>%
fit(data = complaints_train)
Thanks for your message!
I run the code you gave me but I received the same message
Error in app$vspace(new_style$margin-top
%||% 0) :
attempt to apply non-function
I tried to make a reprex but I received the exact same message as well
Error in app$vspace(new_style$margin-top
%||% 0) :
attempt to apply non-function
Thanks for the help!