binomial_test_fl()
関数binomial_test_fl()
は、ビノミアル テストを実行する UDF (ユーザー定義関数)です。
前提条件
- Python プラグインは、クラスター 有効にする必要があります。 これは、関数で使用されるインライン Python に必要です。
- Python プラグインは、データベース 有効にする必要があります。 これは、関数で使用されるインライン Python に必要です。
構文
T | invoke binomial_test_fl(
successes,
trials [,
success_prob [,
alt_hypotheis ]])
構文規則について詳しく知る。
パラメーター
件名 | タイプ | Required | 説明 |
---|---|---|---|
成功 | string |
✔️ | 成功結果の数を含む列の名前。 |
試験 | string |
✔️ | 試行回数の合計を含む列の名前。 |
p_value | string |
✔️ | 結果を格納する列の名前。 |
success_prob | real |
成功確率。 既定値は 0.5 です。 | |
alt_hypotheis | string |
代替仮説は、 two-sided 、 greater 、または less できます。 既定値は、two-sided です。 |
関数定義
関数を定義するには、次のようにコードをクエリ定義関数として埋め込むか、データベースに格納された関数として作成します。
次の let ステートメントを使用して関数を定義。 権限は必要ありません。
重要
let ステートメント単独では実行できません。 その後に 表形式の式ステートメントが続く必要があります。 binomial_test_fl()
の動作例を実行するには、Exampleを参照してください。
let binomial_test_fl = (tbl:(*), successes:string, trials:string, p_value:string, success_prob:real=0.5, alt_hypotheis:string='two-sided')
{
let kwargs = bag_pack('successes', successes, 'trials', trials, 'p_value', p_value, 'success_prob', success_prob, 'alt_hypotheis', alt_hypotheis);
let code = ```if 1:
from scipy import stats
successes = kargs["successes"]
trials = kargs["trials"]
p_value = kargs["p_value"]
success_prob = kargs["success_prob"]
alt_hypotheis = kargs["alt_hypotheis"]
def func(row, prob, h1):
pv = stats.binom_test(row[successes], row[trials], p=prob, alternative=h1)
return pv
result = df
result[p_value] = df.apply(func, axis=1, args=(success_prob, alt_hypotheis), result_type="expand")
```;
tbl
| evaluate python(typeof(*), code, kwargs)
};
// Write your query to use the function here.
例
次の例では、 invoke 演算子 を使用して関数を実行します。
クエリ定義関数を使用するには、埋め込み関数定義の後に呼び出します。
let binomial_test_fl = (tbl:(*), successes:string, trials:string, p_value:string, success_prob:real=0.5, alt_hypotheis:string='two-sided')
{
let kwargs = bag_pack('successes', successes, 'trials', trials, 'p_value', p_value, 'success_prob', success_prob, 'alt_hypotheis', alt_hypotheis);
let code = ```if 1:
from scipy import stats
successes = kargs["successes"]
trials = kargs["trials"]
p_value = kargs["p_value"]
success_prob = kargs["success_prob"]
alt_hypotheis = kargs["alt_hypotheis"]
def func(row, prob, h1):
pv = stats.binom_test(row[successes], row[trials], p=prob, alternative=h1)
return pv
result = df
result[p_value] = df.apply(func, axis=1, args=(success_prob, alt_hypotheis), result_type="expand")
```;
tbl
| evaluate python(typeof(*), code, kwargs)
};
datatable(id:string, x:int, n:int) [
'Test #1', 3, 5,
'Test #2', 5, 5,
'Test #3', 3, 15
]
| extend p_val=0.0
| invoke binomial_test_fl('x', 'n', 'p_val', success_prob=0.2, alt_hypotheis='greater')
出力
ID | x | n | p_val |
---|---|---|---|
テスト #1 | 3 | 5 | 0.05792 |
テスト #2 | 5 | 5 | 0.00032 |
テスト #3 | 3 | 15 | 0.601976790745087 |
この機能はサポートされていません。
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示