View a markdown version of this page

$sigmoid - Amazon DocumentDB

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

$sigmoid

버전 8.0.1에서 새로 추가되었습니다.

Amazon DocumentDB의 $sigmoid 연산자는 로지스틱 시그모이드 함수를 숫자 입력1 / (1 + e^(-x))에 적용합니다. 함수는 모든 실수를 0에서 1 사이의 값에 매핑하여 S자 곡선을 생성합니다. 원시 점수를 확률 또는 관련성 점수로 변환하는 등 값을 0~1 범위로 정규화해야 하는 경우에 유용합니다.

파라미터

  • expression: 숫자 값으로 확인되는 표현식입니다.

예제(MongoDB 쉘)

다음 예제에서는 $sigmoid 연산자를 사용하여 로짓 값을 확률로 변환하는 방법을 보여줍니다.

샘플 문서 생성

db.predictions.insertMany([ {_id: 1, logit: -2}, {_id: 2, logit: 0}, {_id: 3, logit: 2} ]);

쿼리 예제

db.predictions.aggregate([ { $project: { probability: { $sigmoid: "$logit" } } } ]);

출력

[ {_id: 1, probability: 0.11920292202211755}, {_id: 2, probability: 0.5}, {_id: 3, probability: 0.8807970779778823} ]

코드 예제

$sigmoid 연산자 사용에 대한 코드 예제를 보려면 사용하려는 언어의 탭을 선택합니다.

Node.js
const { MongoClient } = require('mongodb'); async function example() { const client = new MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false'); try { await client.connect(); const db = client.db('test'); const collection = db.collection('predictions'); const result = await collection.aggregate([ { $project: { probability: { $sigmoid: "$logit" } } } ]).toArray(); console.log(result); } finally { await client.close(); } } example();
Python
from pymongo import MongoClient def example(): client = MongoClient('mongodb://<username>:<password>@<cluster-endpoint>:27017/?tls=true&tlsCAFile=global-bundle.pem&replicaSet=rs0&readPreference=secondaryPreferred&retryWrites=false') try: db = client['test'] collection = db['predictions'] result = list(collection.aggregate([ {'$project': {'probability': {'$sigmoid': '$logit'}}} ])) print(result) finally: client.close() example()