1
$\begingroup$

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
$\endgroup$

2 Answers 2

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

%*100
(* Out: 72.8592 *)
$\endgroup$
2
$\begingroup$

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]]
sol//FullForm
Rule["Positive",72.85922417349849`]

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

sol[[2]]
"Positive" /. sol

both return your desired number.

$\endgroup$

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.