我试图使用误差幅度计算置信区间,但它给了我一个错误。下面是我写的代码。请帮忙!
import pandas as pd
import scipy.stats as stats
import math
import numpy as np
import warnings
warnings.filterwarnings('ignore')
sample_size=2000
z_critical = stats.norm.ppf(q = 0.95)
# path [File location variable]
#Code starts here
data = pd.read_csv(path)
data_sample = data.sample(n=2000, random_state=0)
sample_mean = data_sample['installment'].mean
sample_std = data_sample['installment'].std()
a = sample_size ** 0.5
margin_of_error = z_critical * (sample_std/44.721)
confidence_interval = (sample_mean + margin_of_error, sample_mean - margin_of_error)
这给出了:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-3f5eda42a1b0> in <module>()
24 # print(type(a))
25 margin_of_error = z_critical * (sample_std/a)
---> 26 confidence_interval = (sample_mean + margin_of_error, sample_mean - margin_of_error)
27 true_mean = data['installment'].mean
28 print(confidence_interval)
TypeError: unsupported operand type(s) for +: 'method' and 'float'
幕布斯6054654
相关分类