python t-test
时间: 2023-09-07 08:13:53 浏览: 116
LDRT指令编码格式-python用k-means聚类算法进行客户分群的实现
T-test is a statistical test used to determine whether there is a significant difference between the means of two groups or samples. In Python, you can use the `scipy.stats` module to perform t-tests. The `ttest_ind` function from this module can be used for independent two-sample t-tests, assuming the samples are normally distributed and have equal variances. Here's an example:
```python
import numpy as np
from scipy import stats
# Generate two random samples
sample1 = np.random.normal(loc=0, scale=1, size=100)
sample2 = np.random.normal(loc=1, scale=1, size=100)
# Perform t-test
t_statistic, p_value = stats.ttest_ind(sample1, sample2)
# Print the result
print("T-statistic:", t_statistic)
print("P-value:", p_value)
```
The `t_statistic` is the calculated t-value, and the `p_value` is the probability of obtaining such results by chance. By comparing the p-value to a significance level (e.g., 0.05), you can determine whether the difference between the means is statistically significant. If the p-value is less than the significance level, it suggests that there is a significant difference between the means of the two samples.
阅读全文