dftest=adfuller(timeseries,autolag='AIC') returndftest[1]<0.05 #差分直到序列平稳 defdifference_until_stationary(df): whilenotdf.apply(test_stationarity).all(): df=df.diff().dropna() returndf #df_diff=difference_until_
returnlower, upper 2. Z-score Z-score为标准分数,测量数据点和平均值的距离,若A与平均值相差2个标准差,Z-score为2。当把Z-score=3作为阈值去剔除异常点时,便相当于3sigma。 defz_score(s): z_score = (s - np.mean(s)) / np.std(...
双样本Z检验:在两个样本z检验中,类似于t检验,我们检查两个独立的数据组并确定两个组的样本均值是否相等。 H0:两组的平均值为0 H1:两组的平均值不为0 示例:我们检查血液之后和血液数据之前的血液数据。(下面是python代码) ztest ,pval1 = stests.ztest(df['bp_before'],x2=df['bp_after'],value=0,...
array(df[['hou']]) t, p = ttest_rel(x, y) print(t, p) 代码语言:javascript 代码运行次数:0 运行 AI代码解释 [9.5629333] [1.80117663e-10] 卡方检验 主要应用场景:通过分析不同类别数据的相对选择频数和占比情况进行差异判断。 核心:一个多分类自变量与另一个多分类因变量。如检验学历(低、中...
python # ^ 测试经纬度坐标转换 df_test = data.head(3) df_test = latitude_longitude_conversion(df_test) print(df_test[['id', 'lon', 'lat', 'level', 'city', 'province']]) powershell id lon lat level city province 0 1 87.83 31.78 5.8 那曲市 西藏自治区 1 2 94.61 37.33 3.4 ...
frequent_patterns import association_rules # 假设df是包含交易数据的DataFrame,'item'是商品列 frequent_itemsets = apriori(df, min_support=0.05, use_colnames=True) rules = association_rules(frequent_itemsets, metric="confidence",min_threshold=0.7) 4.2 协同过滤推荐算法 基于用户的协同过滤是通过计算...
from sklearn.decomposition import PCAfrom sklearn.preprocessing import StandardScalerimport numpy as npimport pandas as pd# 假设df是你的DataFrame,其中包含多列特征数据# 示例数据创建,实际使用时请替换为你的数据np.random.seed(0)df = pd.DataFrame(np.random.rand(100, 5), columns=['Feature1', 'Feat...
首先介绍下bokeh bokeh擅长制作交互式图表,当然在地图展示方面也毫不逊色。Bokeh支持google地图、geojson...
('各列数据类型:\n',df_1.dtypes) df_1: a b c d e f 0 1.0 2022-04-01 1.0 3 test foo 1 1.0 2022-04-01 1.0 3 train foo 2 1.0 2022-04-01 1.0 3 test foo 3 1.0 2022-04-01 1.0 3 train foo 各列数据类型: a float64 b datetime64[ns] c float32 d int32 e category f ...
dataset = pd.get_dummies(df, columns = ['sex', 'cp','fbs','restecg','exang', 'slope','ca', 'thal'])from sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import StandardScalerstandardScaler = StandardScaler()columns_to_scale = ['age', 'trestbps', 'chol', ...