예제 #1
0
 def simulation(self):
     sample = bt.sample_distr(self.nums)
     print("Simulation results: ")
     print(
         "Theoretical mean and simulated mean: {},{}\nTheoretical SE and simulated SE: {},{}"
         .format(float('%.4f' % round(st.s_mean(self.nums), 4)),
                 float('%.4f' % round(st.s_mean(sample), 4)),
                 bt.sample_stand_err(self.nums),
                 float('%.4f' % round(st.s_std(sample), 4))))
     bt.b_plot(sample)
예제 #2
0
def sample_distr(nums):
    sample_props = []
    for _ in range(10000):
        sample = resample(nums)
        sample_props.append(st.s_mean(sample))
    sample_props = np.array(sample_props)
    return sample_props
예제 #3
0
 def test_mean(self):
     self.assertEqual(st.s_mean(self.nums1), 3)
     self.assertEqual(st.s_mean(self.nums2), 5)
     self.assertEqual(st.s_mean(self.nums3), 3.4)
     self.assertEqual(st.s_mean(self.nums4), 5.0)
     self.assertEqual(st.s_mean(self.nums5), 5.4)
     self.assertIsNone(st.s_mean(self.nums6))
     self.assertIsNone(st.s_mean(self.nums7))
예제 #4
0
 def mean(self):
     try:
         if type(self.nums) != np.ndarray:
             raise (NonNumpy)
         if self.nums.shape[0] < 50:
             raise (LengthError)
         return float('%.4f' % round(st.s_mean(self.nums), 4))
     except LengthError:
         print("The array of size {} too short".format(self.nums.shape[0]))
     except NonNumpy:
         print("Inapropriate type, pass numpy array")
예제 #5
0
def p_zscore(x, n, values):
    try:
        if values <= 0:
            raise (nonNegative)
        if n <= 0:
            raise (nonNegative)
        if x == str(x):
            raise (nonText)
        z = (x - st.s_mean(p_obs(n, values))) / st.s_std(p_obs(n, values))
        return z
    except nonNegative:
        print("Error: values and n should be greater than 0")
    except nonText:
        print("Error: not supporting string, please type a number")
예제 #6
0
def knn(tr, te_row, n_neighbors):
    try:
        if n_neighbors <= 0:
            raise (nonNegative)
        if te_row == 0:
            raise (nonZero)
        distances = list()
        for tr_row in tr:
            d = ds.e_distance(te_row, tr_row)
            distances.append((tr_row, d))
        distances.sort(key=lambda tup: tup[1])
        neighbors = list()
        for i in range(n_neighbors):
            neighbors.append(distances[i][0])
        return st.s_mean(neighbors)
    except nonNegative:
        print("Error: n_neighbors should be greater than 0")
    except nonZero:
        print("Error: wrong input")
예제 #7
0
파일: boot.py 프로젝트: volkiza/lab_4
 def mean(self):
     return float('%.4f' % round(st.s_mean(self.nums), 4))
예제 #8
0
def p_zscore(x, n, values):
    z = (x - st.s_mean(p_obs(n, values))) / st.s_std(p_obs(n, values))
    return z