I have this code, and want to extract out just the number. I tried QuantityMagnitude and a transformation rule.

In[1]:= Normal[Classify["Sentiment", "I love this book.", "Probabilities"] 100][[1]]

Out[1]= "Positive" -> 72.8592

2 Answers 2

Classify["Sentiment", "I love this book.", "Probabilities"]["Positive"]
(* Out: 0.728592 *)

(* Out: 72.8592 *)

Whenever you have this kind of problem, use FullForm to figure out what you actually have. Start with your statement, assign it a name, and look at the FullForm:

sol = Normal[Classify["Sentiment", "I love this book.", "Probabilities"] 100][[1]]

so you need to extract the number from the Rule. This can be done several ways:

"Positive" /. sol

both return your desired number.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.