Best Python code snippet using pandera_python
test_ttests.py
Source:test_ttests.py
...129 passed = 0130 n_iter = 500131 for _ in range(n_iter):132 data1 = rng.normal(-5, 2, 100)133 ttest = one_sample_ttest(data1, -5)134 if ttest['P_value'] < .05:135 passed +=1136 self.assertAlmostEqual(passed / n_iter, .05, delta=.01) 137 def test_onesample_left_tailed(self):138 """Testing onesample left tailed."""139 rng = np.random.default_rng(9876138761251)140 passed = 0141 n_iter = 500142 for _ in range(n_iter):143 data1 = rng.normal(15, 1, 100)144 ttest = one_sample_ttest(data1, 15, 'left')145 if ttest['P_value'] < .05:146 passed +=1147 self.assertAlmostEqual(passed / n_iter, .05, delta=.01) 148 def test_one_sample_right_tailed(self):149 """Testing onesample right tailed."""150 rng = np.random.default_rng(615419864354)151 passed = 0152 n_iter = 500153 for _ in range(n_iter):154 data1 = rng.normal(12.2, 1, 100)155 ttest = one_sample_ttest(data1, 12.2, 'right')156 if ttest['P_value'] < .05:157 passed +=1158 self.assertAlmostEqual(passed / n_iter, .05, delta=.01)159class TestMiscTest(unittest.TestCase):160 """Test Fixture for random ttests."""161 def test_fail_tailed_option(self):162 """Testing bad tailed option."""163 with self.assertRaises(ValueError):164 _p_value_and_confidence_intervals(2.3, 100, 'greater')165 def test_confidence_intervals(self):166 """Testing the confidence interval test."""167 # Taken from a T-Test table168 # Two Tailed169 p, ci = _p_value_and_confidence_intervals(2.228, 10, 'two')...
StatsPythonRaw.py
Source:StatsPythonRaw.py
...34 except Exception as inst:35 report_exception(inst)363738def one_sample_ttest(df: pd.DataFrame) -> None:39 """ Perform a one-sample t-test """40 try:41 weight: list = df.iloc[:, 0].tolist()42 results = Stats.OneSampleTTest(25, weight)43 print_results(results, "One-sample t-test.")44 except Exception as inst:45 report_exception(inst)464748def two_sample_ttest(df_x1: pd.DataFrame, df_x2: pd.DataFrame) -> None:49 """ Run more statistical tests """50 try:51 x1: list = df_x1.iloc[:, 0].tolist()52 x2: list = df_x2.iloc[:, 0].tolist()5354 results: dict = Stats.TwoSampleTTest(x1, x2)55 print_results(results, "Two-sample t-test.")56 except Exception as inst:57 report_exception(inst)585960def plot_data(df_x1: pd.DataFrame, df_x2: pd.DataFrame) -> None:61 """ Plot the data """62 x1: list = df_x1.iloc[:, 0].tolist()63 x2: list = df_x2.iloc[:, 0].tolist()64 data: list = [x1, x2]65 66 green_diamond = dict(markerfacecolor='g', marker='D')67 fig1, ax = plt.subplots()68 ax.set_title('US versus Japan Petrol Consumption (mpg)')69 ax.set_xticklabels(['US', 'Japan'])70 ax.boxplot(data, flierprops=green_diamond)71 plt.show()727374if __name__ == "__main__":75 """ Define standard data sets used elsewhere """76 xs: list = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]77 ys: list = [1, 3, 2, 5, 7, 8, 8, 9, 10, 12]7879 run_descriptive_statistics(xs)80 run_linear_regression(xs, ys)8182 ttest_summary_data()8384 filename: str = "../Data/weight.txt"8586 # Read in data frame87 df: pd.DataFrame = pd.read_csv(filename, header=None)8889 one_sample_ttest(df)9091 us_df: pd.DataFrame = pd.read_csv("../Data/us-mpg.txt", header=None)92 jp_df: pd.DataFrame = pd.read_csv("../Data/jp-mpg.txt", header=None)9394 plot_data(us_df, jp_df)95
...
compare-2maps-within-subjects.py
Source:compare-2maps-within-subjects.py
...5from nilearn.image import math_img, mean_img, threshold_img6from nistats.second_level_model import SecondLevelModel7from nistats.thresholding import map_threshold8from nilearn.plotting import plot_glass_brain9def one_sample_ttest(filenames, name):10 design_matrix = pd.DataFrame([1] * len(filenames), columns=['intercept'])11 second_level_model = SecondLevelModel().fit(filenames, design_matrix=design_matrix)12 z_map = second_level_model.compute_contrast(output_type='z_score')13 nib.save(zmap, name + '.nii')14 thmap, threshold1 = map_threshold(z_map, level=.001, height_control='fpr', cluster_threshold=10)15 display = plot_glass_brain(thmap, display_mode='lzry', threshold=0, colorbar=True)16 display.savefig(name + '.png')17 display.close()18def compute_diffmaps(scans_A, scans_B):19 assert len(scans_A) == len(scans_B)20 list_fnames = []21 for sub, a, b in enumerate(zip(scans_A, scans_B)):22 diff = math_img('a - b', img1=a, img=b)23 fname = f'diff_{sub:03}'24 nib.save(fname, diff)25 list_fnames.append(fname)26 return fnames27def compare_2conds_within_subjects(scans_A, scans_B, name):28 files = compute_diffmaps(scans_A, scans_B)...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!