title: R : Error in lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs, : one multinomial or binomial class has 1 or 0 observations; not allowed
body: <p>I am trying to do a sentiment analysis systeme using word2vec and multinomial logistic regression;</p>
  
  <p>Here below the R code : </p>
  
  <pre><code>library(tidyverse)
  library(text2vec)
  library(caret)
  library(glmnet)
  library(ggrepel)
  
  Train_classifier &lt;- read.csv('IRC2.csv',header=T, sep=";")
  
  
  # select only 4 column of the dataframe
  
  Train &lt;- Train_classifier[, c("Note.Reco", "Raison.Reco", "DATE_SAISIE", "idpart")]
  
  #delete rows with empty value columns
  subTrain &lt;- Train[rowSums(Train == '') == 0,]
  subTrain$ID &lt;- seq.int(nrow(subTrain))
  
  # # replacing class values
  subTrain$Note.Reco = ifelse(subTrain$Note.Reco &gt;= 0 &amp; subTrain$Note.Reco &lt;= 4, 0, ifelse(subTrain$Note.Reco &gt;= 5 &amp;
  subTrain$Note.Reco &lt;= 6, 1, ifelse(subTrain$Note.Reco &gt;= 7 &amp; subTrain$Note.Reco &lt;= 8, 2, 3)))
  
  
  
  #Data pre processing
  #Doc2Vec
  
  prep_fun &lt;- tolower
  tok_fun &lt;- word_tokenizer
  
  subTrain[] &lt;- lapply(subTrain, as.character)
  
  reason &lt;- subTrain[['Raison.Reco']][1:10]
  
  
  it_train &lt;- itoken(subTrain$Raison.Reco, 
                     preprocessor = prep_fun, 
                     tokenizer = tok_fun,
                     ids = subTrain$ID,
                     progressbar = TRUE)
  
  
  
  
  
  #creation of vocabulary and term document matrix
    ### fichier  d'apprentissage
  vocab &lt;- create_vocabulary(it_train)
  vectorizer &lt;- vocab_vectorizer(vocab)
  dtm_train &lt;- create_dtm(it_train, vectorizer)
  
  
  
  
  ##Define  tf-idf model 
  
  tfidf &lt;- TfIdf$new()
  # fit the model to the train data and transform it with the fitted model
  dtm_train_tfidf &lt;- fit_transform(dtm_train, tfidf)
  
  
  glmnet_classifier &lt;- cv.glmnet(x = dtm_train_tfidf,
                                 y = subTrain[['Note.Reco']], family = 'multinomial',type.multinomial = "grouped")
  
  
  #plot(glmnet_classifier)
  </code></pre>
  
  <p>Here the structure of the datframe SubTrain : </p>
  
  <pre><code>Note.Reco Raison.Reco DATE_SAISIE idpart ID
  2 3 Toujours bien suivi par mon conseiller 19/03/2014 102853645 1
  3 2 Bon accueil 19/03/2014 1072309 2
  4 3 je suis satisfaite 19/03/2014 191391 3
  6 1 satisfait !! 19/03/2014 14529 4
  7 3 satisfait de ma conseillère 19/03/2014 100065501 5
  </code></pre>
  
  <p>But when I run this code I get this error : </p>
  
  <pre><code>&gt; glmnet_classifier &lt;- cv.glmnet(x = dtm_train_tfidf,
  +                                y = subTrain[['Note.Reco']], family = 'multinomial',type.multinomial = "grouped")
  Error in lognet(x, is.sparse, ix, jx, y, weights, offset, alpha, nobs,  : 
    one multinomial or binomial class has 1 or 0 observations; not allowed
  </code></pre>
  
  <p>As you can see in the dataframe i have no column with 0 and 1  values so I don't why I get this error.</p>
  
  <p>Can you help me to solve this problem? </p>
  
  <p>thank you</p>