翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。
$sigmoid
バージョン 8.0.1 から新規。
Amazon DocumentDB の $sigmoid演算子は、ロジスティックシグモイド関数 1 / (1 + e^(-x))を数値入力に適用します。この関数は、実際の数値を 0~1 の値にマッピングし、S 字曲線を生成します。これは、raw スコアを確率または関連性スコアに変換するなど、値を 0~1 の範囲に正規化する必要がある場合に便利です。
パラメータ
例 (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()