Usage
microsoftml.get_sentiment(cols: [str, dict, list], **kargs)
Description
对自然语言文本进行评分,并评估情绪为正面的概率。
详细信息
变 get_sentiment 换返回自然文本情感为正的概率。 目前仅支持英语。
Arguments
cols
一个用于转换的变量字符串或变量列表。 如果 dict,则这些名称代表将创建的新变量名称。
kargs
发送到计算引擎的其他参数。
Returns
定义转换的对象。
Example
'''
Example with get_sentiment and rx_logistic_regression.
'''
import numpy
import pandas
from microsoftml import rx_logistic_regression, rx_featurize, rx_predict, get_sentiment
# Create the data
customer_reviews = pandas.DataFrame(data=dict(review=[
"I really did not like the taste of it",
"It was surprisingly quite good!",
"I will never ever ever go to that place again!!"]))
# Get the sentiment scores
sentiment_scores = rx_featurize(
data=customer_reviews,
ml_transforms=[get_sentiment(cols=dict(scores="review"))])
# Let's translate the score to something more meaningful
sentiment_scores["eval"] = sentiment_scores.scores.apply(
lambda score: "AWESOMENESS" if score > 0.6 else "BLAH")
print(sentiment_scores)
输出:
Beginning processing data.
Rows Read: 3, Read Time: 0, Transform Time: 0
Beginning processing data.
Elapsed time: 00:00:02.4327924
Finished writing 3 rows.
Writing completed.
review scores eval
0 I really did not like the taste of it 0.461790 BLAH
1 It was surprisingly quite good! 0.960192 AWESOMENESS
2 I will never ever ever go to that place again!! 0.310344 BLAH