import numpy as np from scipy import stats import matplotlib.pyplot as plt from sklearn.model_selection import train_test_split
from sklearn import datasets iris = datasets.load_iris() sep_length = iris.data[:,0] a_1, a_2 = train_test_split(sep_length, test_size=0.4, random_state=0) b_1, b_2 = train_test_split(sep_length, test_size=0.4, random_state=1)
mu1 = np.mean(a_1) mu2 = np.mean(b_1) np.std(a_1) np.std(b_1)
np.float64(0.7912242428472069)
stats.ttest_ind(a_1, b_1, equal_var = False)
TtestResult(statistic=np.float64(0.830066093774641), pvalue=np.float64(0.4076270841218669), df=np.float64(175.8171155714046))
stats.ttest_ind(b_1, a_1, equal_var=False)
TtestResult(statistic=np.float64(-0.830066093774641), pvalue=np.float64(0.4076270841218669), df=np.float64(175.8171155714046))
stats.ttest_ind(a_1, b_1, equal_var=True)
TtestResult(statistic=np.float64(0.830066093774641), pvalue=np.float64(0.4076132965045395), df=np.float64(178.0))
a_1, a_2 = train_test_split(sep_length, test_size=0.4, random_state=0) b_1, b_2 = train_test_split(sep_length, test_size=0.5, random_state=1)
a_1, a_2 = train_test_split(sep_length, test_size=0.4, random_state=0) b_1, b_2 = train_test_split(sep_length, test_size=0.5, random_state=1)
mu1 = np.mean(a_1) mu2 = np.mean(b_1) np.std(a_1) np.std(b_1)
np.float64(0.8016915450055172)
stats.ttest_ind(a_1, b_1, equal_var = False)
TtestResult(statistic=np.float64(0.808385246795547), pvalue=np.float64(0.4200557921940715), df=np.float64(161.80531235936976))
stats.ttest_ind(a_1, b_1, equal_var = False)
TtestResult(statistic=np.float64(0.808385246795547), pvalue=np.float64(0.4200557921940715), df=np.float64(161.80531235936976))
| Summary of t-test Results: Iris Sepal Length | ||
|---|---|---|
| Equal Sample Size | Unequal Sample Size | |
| n₁ | 90 | 90 |
| n₂ | 90 | 75 |
| μ₁ | 5.838888889 | 5.838888889 |
| μ₂ | 5.734444444 | 5.734444444 |
| s₁ | 0.884897288 | 0.884897288 |
| s₂ | 0.791224243 | 0.801691545 |
| Δμ | 0.104444444 | 0.104444444 |
| t | 0.830066094 | 0.808385247 |
| p-value | 0.407627084 | 0.420055792 |