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

Stuck in replication example in Chapter 7 #176

Open
melyale opened this issue Mar 30, 2022 · 2 comments
Open

Stuck in replication example in Chapter 7 #176

melyale opened this issue Mar 30, 2022 · 2 comments

Comments

@melyale
Copy link

melyale commented Mar 30, 2022

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!

@EmilHvitfeldt
Copy link
Owner

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)

@melyale
Copy link
Author

melyale commented Mar 31, 2022

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants