All Products
Search
Document Center

Platform For AI:Two-sample t-test

Last Updated:Apr 02, 2026

The Two-Sample T-Test component tests whether the population means from two samples are significantly different, using standard statistical hypothesis testing.

Choose a test type

The component supports two test types. Choose based on how the two samples relate to each other:

Test type Use when Requirements
Independent t-test The two samples are unrelated — for example, a test group vs. a control group Samples must be independent; data should follow a normal distribution
Paired t-test Each observation in Sample 1 corresponds to one in Sample 2 — for example, before/after measurements on the same subject Samples must be the same size and paired by row

Configure the component

Method 1: Configure on the pipeline page

Configure parameters for the Two Sample T Test component on the Machine Learning Designer pipeline page.

Tab Parameter Description
Fields setting Sample 1 Column The column that contains Sample 1.
Sample 2 Column The column that contains Sample 2.
Parameters setting T Test Type The type of t-test to run. Valid values: Independent T Test, Paired T Test.
Alternative Hypothesis Type The direction of the alternative hypothesis. Valid values: two.sided, less, greater. See Alternative hypothesis type.
Confidence Level The confidence level for the result interval. Valid values: 0.8, 0.9, 0.95, 0.99, 0.995, 0.999.
Hypothesized Mean The hypothesized mean. Default: 0.
Variances of Two Populations Are Equal Whether to assume equal variances. Valid values: true, false. If unsure, set to false to use the Welch t-test, which is robust when variances differ. Default: false.
Cores Number of CPU cores. Must be a positive integer from 1 to 9999. Use together with Memory Size Per Core.
Memory Size Per Core Memory per core in MB. Must be a positive integer from 1024 to 65536.

Alternative hypothesis type

Value Tests whether
two.sided A population mean is either greater than or less than a hypothesized value
less A population mean is less than a hypothesized value
greater A population mean is greater than a hypothesized value

Method 2: Use PAI commands

Run the Two-Sample T-Test by calling the t_test algorithm with a PAI command. Use the SQL Script component to run PAI commands in a pipeline.

pai -name t_test
    -project algo_public
    -DxTableName=pai_t_test_all_type
    -DxColName=col1_double
    -DxTablePartitions=ds=2010/dt=1
    -DyTableName=pai_t_test_all_type
    -DyColName=col1_double
    -DyTablePartitions=ds=2010/dt=1
    -DoutputTableName=pai_t_test_out
    -Dalternative=less
    -Dmu=47
    -DconfidenceLevel=0.95
    -Dpaired=false
    -DvarEqual=true
Parameter Required Description Default
xTableName Yes Name of input table x.
xColName Yes Column in input table x used for the test. Must be DOUBLE or INT type.
xTablePartitions No Partitions in input table x to include. Supported formats: partition_name=value (single level), name1=value1/name2=value2 (multi-level). Separate multiple partitions with commas. All partitions
yTableName Yes Name of input table y.
yColName Yes Column in input table y used for the test. Must be DOUBLE or INT type.
yTablePartitions No Partitions in input table y to include. Same format as xTablePartitions. All partitions
paired No true for paired t-test; false for independent t-test. false
alternative No Direction of the alternative hypothesis. Valid values: two.sided, less, greater. two.sided
mu No Hypothesized mean. Must be DOUBLE type. 0
varEqual No Whether to assume equal variances. Set to false to use the Welch t-test when variances may differ. false
confidenceLevel No Confidence level for the result interval. Valid values: 0.8, 0.9, 0.95, 0.99, 0.995, 0.999. 0.95
coreNum No Number of CPU cores. Valid values: 1 to 9999. Use with memSizePerCore. System default
memSizePerCore No Memory per core in MB. Valid values: 1024 to 65536. System default
lifecycle No Lifecycle of the output table.
Note

For non-partitioned tables, omit coreNum and memSizePerCore and let the system determine resource allocation. To calculate resources manually, use the following function:

def CalcCoreNumAndMem(row, centerCount, kOneCoreDataSize=1024):
    """Calculate the number of cores and memory size per core.

    Args:
        row: Number of rows in the input table.
        centerCount: Number of columns in the input table.
        kOneCoreDataSize: Amount of data each core can process, in MB. Default: 1024.

    Returns:
        coreNum, memSizePerCore
    """
    kMBytes = 1024.0 * 1024.0
    # Number of cores
    coreNum = max(1, int(row * 2 * 8 / kMBytes / kOneCoreDataSize))
    # Memory per core
    memSizePerCore = max(1024, int(kOneCoreDataSize * 2))
    return coreNum, memSizePerCore

Output fields

The output table contains a single row and column in JSON format. The following table describes each field:

Field Description
AlternativeHypthesis The alternative hypothesis tested.
ConfidenceInterval The confidence interval for the difference in population means at the specified confidence level.
ConfidenceLevel The confidence level used.
alpha The significance level (1 − confidence level). For example, alpha is 0.05 when the confidence level is 0.95.
df Degrees of freedom used in the t-distribution.
mean of the differences The observed difference between the sample means.
p The p-value. If p is less than alpha — for example, p < 0.05 when the confidence level is 0.95 — the difference is statistically significant and you should reject the null hypothesis.
t The t-statistic.

Example

Prepare test data

create table pai_test_input as
select * from
(
  select 1 as f0, 2 as f1
  union all
  select 1 as f0, 3 as f1
  union all
  select 1 as f0, 4 as f1
  union all
  select 0 as f0, 3 as f1
  union all
  select 0 as f0, 4 as f1
) tmp;

PAI command

pai -name t_test
    -project algo_public
    -DxTableName=pai_test_input
    -DxColName=f0
    -DyTableName=pai_test_input
    -DyColName=f1
    -DyTablePartitions=ds=2010/dt=1
    -DoutputTableName=pai_t_test_out
    -Dalternative=less
    -Dmu=47
    -DconfidenceLevel=0.95
    -Dpaired=false
    -DvarEqual=true

Output

{
    "AlternativeHypthesis": "difference in means not equals to 0",
    "ConfidenceInterval": "(-2.5465, -0.4535)",
    "ConfidenceLevel": 0.95,
    "alpha": 0.05000000000000004,
    "df": 19,
    "mean of the differences": -1.5,
    "p": 0.008000000000000007,
    "t": -3
}

In this example, p = 0.008 < alpha = 0.05, so the difference in means is statistically significant at the 95% confidence level. Reject the null hypothesis.