基于XGBOOST模型预测货物运输耗时 - Part 2 通过方差分析了解文本型变量与数值型目标变量的关系

news2024/9/28 15:25:16
  • 在分析数据之前,我们需要剔除异常值的影响,也就是在某个分组情况下,标准差过大(标准差越大,证明情况越不稳定),如果标准差比较小,就算是最小值和最大值差的比较大,我也认为他是一个比较平稳的波动。
  • 方差分析这个老师讲的很好:[https://www.bilibili.com/video/BV1jB4y1676T/?spm_id_from=333.788&vd_source=642d9a85cff4a726a7de10f2383987df]
    -

Step 6:Reduce Std.

  • assure data stability
# 按 Category 列分组并计算每个分组的标准差
grouped_data = df_replen.groupby(['mot','country','priority','cc']).agg({'lt_pu_pod':['std','count',lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]})
# 打印结果
grouped_data = grouped_data.reset_index()
grouped_data.columns = ['mot','country','priority','cc','std','count','quantile_90','quantile_10']
grouped_data
motcountrypriorityccstdcountquantile_90quantile_10
0SEAAE40ADNaN110.36010.360

3150 rows × 8 columns

for group_i in grouped_data.index:
    group_mot = grouped_data.loc[group_i,'mot']
    group_country = grouped_data.loc[group_i,'country']
    group_priority = grouped_data.loc[group_i,'priority']
    group_cc = grouped_data.loc[group_i,'cc']
    
    group_std = grouped_data.loc[group_i,'std']
    group_count = grouped_data.loc[group_i,'count']
    group_quantile_90 = grouped_data.loc[group_i,'quantile_90']
    group_quantile_10 = grouped_data.loc[group_i,'quantile_10']
    
    if group_count>=5 and group_std>=8:
        index_replen = df_replen[(df_replen['mot']==group_mot) & (df_replen['country']==group_country) & (df_replen['priority']==group_priority)
                 & ((df_replen['lt_pu_pod']>=group_quantile_90) | (df_replen['lt_pu_pod']<=group_quantile_10))
                 ].index
        for repl_i in index_replen:
            df_replen.loc[repl_i,'Type_'] = 'Y'
df_replen_1 = df_replen[df_replen['Type_'].isnull()]
df_replen_1 = df_replen_1[~df_replen_1['hawb'].isnull() & ~df_replen_1['ts_atd'].isnull() & ~df_replen_1['cc'].isnull() & ~df_replen_1['weight'].isnull()].reset_index().drop('index',axis=1)
df_replen_1.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 103166 entries, 0 to 103165
Data columns (total 24 columns):
 #   Column             Non-Null Count   Dtype  
---  ------             --------------   -----  
 0   hawb               103233 non-null  object 
 1   mot                103233 non-null  object 
 2   geo                103166 non-null  object 
 3   country            103166 non-null  object 
 4   shippingfrequency  103166 non-null  object 
 5   isgreen            103166 non-null  object 
 6   priority           103166 non-null  object 
 7   forwarder          103166 non-null  object 
 8   cc                 93166 non-null  object 
 9   dn_gr_status       103166 non-null  object 
 10  volume             103166 non-null  float64
 11  weight             103166 non-null  float64
 12  dn_seq_qty         103166 non-null  float64
 13  ts_pu              103166 non-null  object 
 14  ts_atd             103166 non-null  object 
 15  ts_ata             103038 non-null  object 
 16  ts_cc              102855 non-null  object 
 17  ts_pod             103166 non-null  object 
 18  ts_atd_pre_2_date  103166 non-null  object 
 19  lt_pu_pod          103166 non-null  float64
 20  lt_pu_atd          103166 non-null  float64
 21  lt_atd_ata         103166 non-null  float64
 22  data_source        103166 non-null  object 
 23  Type_              0 non-null       object 
dtypes: float64(6), object(18)
memory usage: 18.9+ MB
# 按 Category 列分组并计算每个分组的标准差
grouped_data_1 = df_replen_1.groupby(['mot','country','priority','cc']).agg({'lt_pu_pod':['std','count',lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]})
# 打印结果
grouped_data_1 = grouped_data_1.reset_index()
grouped_data_1.columns = ['mot','country','priority','cc','std','count','quantile_90','quantile_10']
grouped_data_1
motcountrypriorityccstdcountquantile_90quantile_10
0AIRER30ADNaN116.33316.333

3017 rows × 8 columns

print('Reduce std','As is:【',grouped_data['std'].mean(),'-->','】To be:【',grouped_data_1['std'].mean(),'】')
Reduce std As is:【 4.281785006069334 --> 】To be:【 2.748443864082784 】

Step 7:Research Relationship

research weight&leadtime relationship

for mot in df_replen_1['geo'].unique().tolist():
    plt.figure(figsize=(10, 6))
    sns.heatmap(data=df_replen_1[(df_replen_1['geo']==mot)].corr(), cmap='coolwarm', annot=True, fmt=".2f", cbar=True)
    plt.title("Correlation between volume,qty,weight and lt_pu_pod mot")
    plt.xlabel("{0}".format(mot))
    plt.ylabel("country")
    plt.xticks(rotation=45)
    plt.show()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述在这里插入图片描述

for mot in df_replen_1['mot'].unique().tolist():
    plt.figure(figsize=(10, 6))
    sns.heatmap(data=df_replen_1[(df_replen_1['mot']==mot)].corr(), cmap='coolwarm', annot=True, fmt=".2f", cbar=True)
    plt.title("Correlation between volume,qty,weight and lt_pu_pod mot")
    plt.xlabel("{0}".format(mot))
    plt.ylabel("country")
    plt.xticks(rotation=45)
    plt.show()

在这里插入图片描述在这里插入图片描述在这里插入图片描述

  • Consequently:weight&dn_seq_qty is Strong correlation relationship

  • but weight&leadtime is weak correlation relationship

# 计算相关系数
corr = df_replen_1.corr().iloc[0,1]

# 按照运输类型分组并绘制散点图
for t, group in df_replen_1.groupby('mot'):
    plt.scatter(group['volume'], group['lt_pu_atd'], label=t)
    corr = group.corr().iloc[0,2]
    # 添加图标题和坐标轴标签
    plt.title(f"Weight vs Time ({t.title()}) (Correlation: {corr:.2f})")
    plt.xlabel("volume")
    plt.ylabel("Time")

    # 添加图例
    plt.legend()

    # 显示图形
    plt.show()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

# 计算相关系数
corr = df_replen_1.corr().iloc[0,1]

# 按照运输类型分组并绘制散点图
for t, group in df_replen_1.groupby('mot'):
    plt.scatter(group['weight'], group['lt_pu_pod'], label=t)
    corr = group.corr().iloc[0,2]
    # 添加图标题和坐标轴标签
    plt.title(f"Weight vs Time ({t.title()}) (Correlation: {corr:.2f})")
    plt.xlabel("Weight")
    plt.ylabel("Time")

    # 添加图例
    plt.legend()

    # 显示图形
    plt.show()

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

方差1、GEO与LT_PU_POD的关联性

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

方差分析

  • 原假设:每个GEO直接与LT_PU_POD没有关联性

在独立样本T检验中,自由度的计算方法与样本数量有关。如果你有4个geo,假设每个geo对应一个独立的样本组别,那么自由度的计算如下:

自由度 = (样本1的观测数量 - 1) + (样本2的观测数量 - 1) + … + (样本4的观测数量 - 1)

具体计算时,需要知道每个geo对应的样本数量。假设分别为n1、n2、n3、n4,则自由度为 (n1 - 1) + (n2 - 1) + (n3 - 1) + (n4 - 1)。

df_replen_1.groupby(['geo']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
geolt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0EA3.444474248.9408076.3517.533.98
1BrazilNaN17.8300007.837.837.83
2MX8.325913224767.9956706.349.433.87
3NE7.462291754215.75251014.3226.357.39
4PJ5.33368619.6332068.1217.435.43
from scipy.stats import f_oneway

# 提取不同地理位置的运输耗时数据
geo1_data = df_replen_1[df_replen_1['geo'] == 'AP']['lt_pu_pod']
geo2_data = df_replen_1[df_replen_1['geo'] == 'EMEA']['lt_pu_pod']
geo3_data = df_replen_1[df_replen_1['geo'] == 'LAS']['lt_pu_pod']
geo4_data = df_replen_1[df_replen_1['geo'] == 'NA']['lt_pu_pod']

# 执行单因素方差分析
f_stat, p_value = f_oneway(geo1_data, geo2_data, geo3_data, geo4_data)

# 输出分析结果
print("单因素方差分析结果:")
print("F统计量:", f_stat)
print("p值:", p_value)
单因素方差分析结果:
F统计量: 2676.3050920291266
p值: 0.0
  • 当p值等于0时,通常表示在检验中观察到的差异极其显著。这意味着在假设检验中,得到的样本数据非常不可能出现,或者可以说观察到的差异非常显著,远远超过了我们预期的随机差异。

方差2、MOT与LT_PU_POD的关联性

from scipy.stats import f_oneway

# 提取不同地理位置的运输耗时数据
mot1_data = df_replen_1[df_replen_1['mot'] == 'AIR']['lt_pu_pod']
mot2_data = df_replen_1[df_replen_1['mot'] == 'SEA']['lt_pu_pod']
mot3_data = df_replen_1[df_replen_1['mot'] == 'TRUCK']['lt_pu_pod']

# 执行单因素方差分析
f_stat, p_value = f_oneway(mot1_data, mot2_data, mot3_data)

# 输出分析结果
print("单因素方差分析结果:")
print("F统计量:", f_stat)
print("p值:", p_value)
单因素方差分析结果:
F统计量: 42951.20078674416
p值: 0.0
df_replen_1.groupby(['mot']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
motlt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0SEA3.3333900397.9132566.8113.344.13
1SEA10.3070481075245.99920.5941.5213.28
2TRUCK0.90333623754.2156513.995.013.40

方差3、priority与LT_PU_POD的关联性

from scipy.stats import f_oneway

# 提取不同地理位置的运输耗时数据
mot1_data = df_replen_1[df_replen_1['priority'] == '20']['lt_pu_pod']
mot2_data = df_replen_1[df_replen_1['priority'] == '40']['lt_pu_pod']
mot3_data = df_replen_1[df_replen_1['priority'] == '60']['lt_pu_pod']
mot4_data = df_replen_1[df_replen_1['priority'] == 'PPF']['lt_pu_pod']

# 执行单因素方差分析
f_stat, p_value = f_oneway(mot1_data, mot2_data, mot3_data,mot4_data)

# 输出分析结果
print("单因素方差分析结果:")
print("F统计量:", f_stat)
print("p值:", p_value)
单因素方差分析结果:
F统计量: 6366.387676680081
p值: 0.0
df_replen_1.groupby(['priority']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
prioritylt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0335.207475160008.5010196.8814.324.11
1214.303070668187.9838866.8413.384.08
28111.2947881986515.00900613.2429.424.45
3TUU2.2369964835.5698144.877.803.77

方差4、cc与LT_PU_POD的关联性

df_replen_1.groupby(['cc']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
cclt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0AD7.705418219010.1731467.11520.4604.219
1AN6.97200419949.1716506.85017.3574.080
2BA14.73170513026.28707721.14048.35713.240
3BC7.25939329369.8190537.12019.8104.140
4BI11.435282108920.74596018.56037.4308.948
from scipy.stats import f_oneway

# 创建一个空列表用于存储各个分类的数据
data_list = []

# 遍历每个分类,提取对应的数据并添加到列表中
for category in df_replen_1['cc'].unique().tolist():
    category_data = df_replen_1[df_replen_1['cc'] == category]['lt_pu_pod']
    data_list.append(category_data)

# 绘制箱线图
plt.figure(figsize=(25, 6))
sns.boxplot(data=data_list)
plt.xlabel('Category')
plt.ylabel('lt_pu_pod')
plt.title('Boxplot of lt_pu_pod for different categories')
plt.xticks(range(len(df_replen_1['cc'].unique().tolist())), df_replen_1['cc'].unique().tolist(),rotation=45)
plt.show()

# 执行方差分析
f_stat, p_value = f_oneway(*data_list)

# 输出结果
print("F统计量:", f_stat)
print("p值:", p_value)

在这里插入图片描述

F统计量: 165.67483191021196
p值: 0.0

方差5、isgreen与LT_PU_POD的关联性

df_replen_1.groupby(['isgreen']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
isgreenlt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0GL16.818674581010.3401277.5520.315.05
1GL20.83661264.2100004.744.763.13
# 创建一个空列表用于存储各个分类的数据
data_list = []

# 遍历每个分类,提取对应的数据并添加到列表中
for category in df_replen_1['isgreen'].unique().tolist():
    category_data = df_replen_1[df_replen_1['isgreen'] == category]['lt_pu_pod']
    data_list.append(category_data)

# 绘制箱线图
plt.figure(figsize=(25, 6))
sns.boxplot(data=data_list)
plt.xlabel('Category')
plt.ylabel('lt_pu_pod')
plt.title('Boxplot of lt_pu_pod for different categories')
plt.xticks(range(len(df_replen_1['isgreen'].unique().tolist())), df_replen_1['isgreen'].unique().tolist(),rotation=45)
plt.show()

# 执行方差分析
f_stat, p_value = f_oneway(*data_list)

# 输出结果
print("F统计量:", f_stat)
print("p值:", p_value)

在这里插入图片描述

F统计量: 49.45782385934109
p值: 1.2062238051192215e-41

方差6、shippingfrequency与LT_PU_POD的关联性

df_replen_1.groupby(['shippingfrequency']).agg({'lt_pu_pod':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
shippingfrequencylt_pu_pod
stdcountmean<lambda_0><lambda_1><lambda_2>
0Bi-Weekly(Thu)17.66472713024.45323115.94054.189.731
1Bi-Weekly(Tue)9.3063142936.93827635.59049.5723.954
2Bi-Weekly(Wed)2.271108164.7343753.8405.483.820
3Daily6.448783353227.8900036.76010.384.400
from scipy.stats import f_oneway

# 创建一个空列表用于存储各个分类的数据
data_list = []

# 遍历每个分类,提取对应的数据并添加到列表中
for category in df_replen_1['shippingfrequency'].unique().tolist():
    category_data = df_replen_1[df_replen_1['shippingfrequency'] == category]['lt_pu_pod']
    data_list.append(category_data)

# 绘制箱线图
plt.figure(figsize=(25, 6))
sns.boxplot(data=data_list)
plt.xlabel('Category')
plt.ylabel('lt_pu_pod')
plt.title('Boxplot of lt_pu_pod for different categories')
plt.xticks(range(len(df_replen_1['shippingfrequency'].unique().tolist())), df_replen_1['shippingfrequency'].unique().tolist(),rotation=45)
plt.show()

# 执行方差分析
f_stat, p_value = f_oneway(*data_list)

# 输出结果
print("F统计量:", f_stat)
print("p值:", p_value)

在这里插入图片描述

F统计量: 2693.5635083145007
p值: 0.0

方差7、forwarder与LT_PU_POD的关联性

# 创建一个空列表用于存储各个分类的数据
data_list = []

# 遍历每个分类,提取对应的数据并添加到列表中
for category in df_replen_1['forwarder'].unique().tolist():
    category_data = df_replen_1[df_replen_1['forwarder'] == category]['lt_pu_pod']
    data_list.append(category_data)

# 绘制箱线图
plt.figure(figsize=(25, 6))
sns.boxplot(data=data_list)
plt.xlabel('Category')
plt.ylabel('lt_pu_pod')
plt.title('Boxplot of lt_pu_pod for different categories')
plt.xticks(range(len(df_replen_1['forwarder'].unique().tolist())), df_replen_1['forwarder'].unique().tolist(),rotation=45)
plt.show()

# 执行方差分析
f_stat, p_value = f_oneway(*data_list)

# 输出结果
print("F统计量:", f_stat)
print("p值:", p_value)
F统计量: 12060.165772842343
p值: 0.0
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

# 选择需要的特征列
cols = ['geo', 'country', 'mot', 'volume', 'lt_pu_pod']

# 提取对应的数据子集
data_subset = df_replen_1[cols]

# 计算每个geo下每个country和每个mot的volume与lt_pu_pod的相关性
correlation_matrix = data_subset.groupby(['geo', 'country', 'mot']).corr().loc[:, 'volume'].unstack()

# 绘制热力图
plt.figure(figsize=(24, 16))
sns.heatmap(data=correlation_matrix, cmap='coolwarm', annot=True, fmt=".2f", cbar=True)
plt.title("Correlation between volume and lt_pu_pod by geo, country, and mot")
plt.xlabel("mot")
plt.ylabel("country")
plt.xticks(rotation=45)
plt.show()

在这里插入图片描述

Step 5:Research climate&lt_pu_atd

df_replen_2 = df_replen_1.copy()
df_replen_2['ts_pu_date'] = df_replen_2['ts_pu'].map(lambda x:pd.to_datetime(x).strftime('%Y-%m-%d'))
df_replen_open['ts_pu_date'] = df_replen_open['ts_pu'].map(lambda x:pd.to_datetime(x).strftime('%Y-%m-%d'))
for rep_index in df_replen_2.index:
    ts_pu = (pd.to_datetime(df_replen_2.loc[rep_index,'ts_atd_pre_2_date']))
    ts_atd = (pd.to_datetime(df_replen_2.loc[rep_index,'ts_atd']))
    if pd.isna(ts_atd)==False:
        if ts_pu > ts_atd:
#             print(rep_index)
            ts_atd = (pd.to_datetime(df_replen_2.loc[rep_index,'ts_pu']) + datetime.timedelta(1.5))
    if pd.isna(ts_atd):
        ts_atd = (pd.to_datetime(df_replen_2.loc[rep_index,'ts_pu']) + datetime.timedelta(1.5))
    df_climate_tmp = df_climate_workday[(df_climate_workday['Date']<=ts_atd) & (df_climate_workday['Date']>=ts_pu)]
    holiday_count = len(df_climate_tmp[df_climate_tmp['weekday_cat']=='holiday'])
    climate_count = len(df_climate_tmp[df_climate_tmp['Alarm_info_cat']=='Abnormal climate'])
    # 判断期间有多少天假期
    if holiday_count == 0:
        df_replen_2.loc[rep_index,'holiday_count'] = '^== 0 hldys'
    if holiday_count == 1:
        df_replen_2.loc[rep_index,'holiday_count'] = '^== 1 hldys'
    if holiday_count == 2:
        df_replen_2.loc[rep_index,'holiday_count'] = '^== 2 hldys'
    if holiday_count > 2 and holiday_count <=7:
        df_replen_2.loc[rep_index,'holiday_count'] = '^<= 7 hldys'
    if holiday_count > 7 and holiday_count <=14:
        df_replen_2.loc[rep_index,'holiday_count'] = '^<= 14 hldys'
    if holiday_count > 14:
        df_replen_2.loc[rep_index,'holiday_count'] = '^> 14 hldys'
    
    # 判断期间有多少天恶劣天气
    if climate_count == 0:
        df_replen_2.loc[rep_index,'climate_count'] = '^== 0 abnr'
    if climate_count == 1:
        df_replen_2.loc[rep_index,'climate_count'] = '^== 1 abnr'
    if climate_count == 2:
        df_replen_2.loc[rep_index,'climate_count'] = '^== 2 abnr'
    if climate_count > 2 and climate_count <=7:
        df_replen_2.loc[rep_index,'climate_count'] = '^<= 7 abnr'
    if climate_count > 7 and climate_count <=14:
        df_replen_2.loc[rep_index,'climate_count'] = '^<= 14 abnr'
    if climate_count > 14:
        df_replen_2.loc[rep_index,'climate_count'] = '^> 14 abnr'
for rep_index in df_replen_open.index:
    ts_pu = (pd.to_datetime(df_replen_open.loc[rep_index,'ts_atd_pre_2_date']))
    ts_atd = (pd.to_datetime(df_replen_open.loc[rep_index,'ts_atd']))
    if pd.isna(ts_atd)==False:
        if ts_pu > ts_atd:
#             print(rep_index)
            ts_atd = (pd.to_datetime(df_replen_open.loc[rep_index,'ts_pu']) + datetime.timedelta(1.5))
    if pd.isna(ts_atd):
        ts_atd = (pd.to_datetime(df_replen_open.loc[rep_index,'ts_pu']) + datetime.timedelta(1.5))
    df_climate_tmp = df_climate_workday[(df_climate_workday['Date']<=ts_atd) & (df_climate_workday['Date']>=ts_pu)]
    holiday_count = len(df_climate_tmp[df_climate_tmp['weekday_cat']=='holiday'])
    climate_count = len(df_climate_tmp[df_climate_tmp['Alarm_info_cat']=='Abnormal climate'])
    # 判断期间有多少天假期
    if holiday_count == 0:
        df_replen_open.loc[rep_index,'holiday_count'] = '^== 0 hldys'
    if holiday_count == 1:
        df_replen_open.loc[rep_index,'holiday_count'] = '^== 1 hldys'
    if holiday_count == 2:
        df_replen_open.loc[rep_index,'holiday_count'] = '^== 2 hldys'
    if holiday_count > 2 and holiday_count <=7:
        df_replen_open.loc[rep_index,'holiday_count'] = '^<= 7 hldys'
    if holiday_count > 7 and holiday_count <=14:
        df_replen_open.loc[rep_index,'holiday_count'] = '^<= 14 hldys'
    if holiday_count > 14:
        df_replen_open.loc[rep_index,'holiday_count'] = '^> 14 hldys'
    
    # 判断期间有多少天恶劣天气
    if climate_count == 0:
        df_replen_open.loc[rep_index,'climate_count'] = '^== 0 abnr'
    if climate_count == 1:
        df_replen_open.loc[rep_index,'climate_count'] = '^== 1 abnr'
    if climate_count == 2:
        df_replen_open.loc[rep_index,'climate_count'] = '^== 2 abnr'
    if climate_count > 2 and climate_count <=7:
        df_replen_open.loc[rep_index,'climate_count'] = '^<= 7 abnr'
    if climate_count > 7 and climate_count <=14:
        df_replen_open.loc[rep_index,'climate_count'] = '^<= 14 abnr'
    if climate_count > 14:
        df_replen_open.loc[rep_index,'climate_count'] = '^> 14 abnr'
df_replen_2.groupby(['holiday_count']).agg({'lt_pu_atd':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
holiday_countlt_pu_atd
stdcountmean<lambda_0><lambda_1><lambda_2>
0^<= 7 hldys2.05380922044.7935934.407.542.82
1^== 0 hldys2.184254528962.6496062.125.440.44
2^== 1 hldys2.411114282552.4618882.114.610.47
3^== 2 hldys1.749583198113.2935602.905.131.75
# 创建一个空列表用于存储各个分类的数据
for mot in df_replen_2['mot'].unique().tolist():
    # 遍历每个分类,提取对应的数据并添加到列表中
    data_list = []
    for category in df_replen_2[df_replen_2['mot']==mot]['climate_count'].unique().tolist():
        category_data = df_replen_2[df_replen_2['climate_count'] == category]['lt_pu_pod']
        data_list.append(category_data)

    # 绘制箱线图
    plt.figure(figsize=(25, 6))
    sns.boxplot(data=data_list)
    plt.xlabel('Category')
    plt.ylabel('lt_pu_pod')
    plt.title('{0} Boxplot of lt_pu_pod for different categories'.format(mot))
    plt.xticks(range(len(df_replen_2[df_replen_2['mot']==mot]['climate_count'].unique().tolist())), df_replen_2[df_replen_2['mot']==mot]['climate_count'].unique().tolist(),rotation=45)
    plt.show()

    # 执行方差分析
    f_stat, p_value = f_oneway(*data_list)

    # 输出结果
    print("F统计量:", f_stat)
    print("p值:", p_value)

在这里插入图片描述

F统计量: 168.19664286910245
p值: 8.91244672555718e-109

在这里插入图片描述

F统计量: 168.19664286910245
p值: 8.91244672555718e-109

在这里插入图片描述

F统计量: 168.19664286910245
p值: 8.91244672555718e-109
import matplotlib.pyplot as plt
import seaborn as sns
# 创建一个空列表用于存储各个分类的数据
for mot in df_replen_2['mot'].unique().tolist():
    # 遍历每个分类,提取对应的数据并添加到列表中
    data_list = []
    for category in df_replen_2[df_replen_2['mot']==mot]['holiday_count'].unique().tolist():
        category_data = df_replen_2[df_replen_2['holiday_count'] == category]['lt_pu_pod']
        data_list.append(category_data)

    # 绘制箱线图
    plt.figure(figsize=(25, 6))
    sns.boxplot(data=data_list)
    plt.xlabel('Category')
    plt.ylabel('lt_pu_pod')
    plt.title('{0} Boxplot of lt_pu_pod for different categories'.format(mot))
    plt.xticks(range(len(df_replen_2[df_replen_2['mot']==mot]['holiday_count'].unique().tolist())), df_replen_2[df_replen_2['mot']==mot]['holiday_count'].unique().tolist(),rotation=45)
    plt.show()

    # 执行方差分析
    f_stat, p_value = f_oneway(*data_list)

    # 输出结果
    print("F统计量:", f_stat)
    print("p值:", p_value)

在这里插入图片描述

F统计量: 134.89417962378948
p值: 3.1763774706854116e-87

在这里插入图片描述

F统计量: 134.89417962378948
p值: 3.1763774706854116e-87

在这里插入图片描述

F统计量: 82.45295180623998
p值: 1.6609295478352026e-36
df_replen_2['ts_pu_date'] = pd.to_datetime(df_replen_2['ts_pu_date'])
df_replen_open['ts_pu_date'] = pd.to_datetime(df_replen_open['ts_pu_date'])
df_replen_2 = pd.merge(df_replen_2,df_climate_workday[['Date','Alarm_info_cat','weekday_cat','Week','weekday']],left_on='ts_pu_date',right_on='Date',how='left').drop('Date',axis=1).rename(columns={'天气':'climate','分类':'climate_category'})
df_replen_open = pd.merge(df_replen_open,df_climate_workday[['Date','Alarm_info_cat','weekday_cat','Week','weekday']],left_on='ts_pu_date',right_on='Date',how='left').drop('Date',axis=1).rename(columns={'天气':'climate','分类':'climate_category'})
df_replen_2['lt_pu_ata'] = (pd.to_datetime(df_replen_1['ts_ata']) - pd.to_datetime(df_replen_1['ts_pu'])).astype('timedelta64[D]').astype(float)
df_replen_2['lt_pu_atd'] = (pd.to_datetime(df_replen_1['ts_atd']) - pd.to_datetime(df_replen_1['ts_pu'])).astype('timedelta64[D]').astype(float)
df_climate_workday
DateWeekmaximum_temperatureminimum_temperatureclimatewind_directioncityis_workdayis_holidayholiday_nameweekdayweekday_catdate_alarmAlarm_infoAlarm_info_catunic_versionrank_1
02022-01-01星期六0℃-9℃多云西风 2级上海01New year5holidayNaTNoneNone2023-05-18 16:25:251
12022-01-02星期日8℃-4℃多云西风 3级上海006holidayNaTNoneNone2023-05-18 16:25:251
22022-01-03星期一13℃6℃东南风 2级上海01New Year shift0holidayNaTNoneNone2023-05-18 16:25:251
32022-01-04星期二13℃9℃多云东北风 1级上海101workdayNaTNoneNone2023-05-18 16:25:251

502 rows × 17 columns


# 创建一个空列表用于存储各个分类的数据
for mot in df_replen_2['mot'].unique().tolist():
    # 遍历每个分类,提取对应的数据并添加到列表中
    data_list = []
    for category in df_replen_2[(df_replen_2['mot']==mot) & (~df_replen_2['weekday'].isnull())]['weekday'].unique().tolist():
        category_data = df_replen_2[(df_replen_2['mot']==mot) & (~df_replen_2['weekday'].isnull()) & (df_replen_2['weekday'] == category)]['lt_pu_pod']
        data_list.append(category_data)

    # 绘制箱线图
    plt.figure(figsize=(25, 6))
    sns.boxplot(data=data_list)
    plt.xlabel('Category')
    plt.ylabel('lt_pu_pod')
    plt.title('{0} Boxplot of lt_pu_pod for different categories'.format(mot))
    plt.xticks(range(len(df_replen_2[df_replen_2['mot']==mot]['weekday'].unique().tolist())), df_replen_2[df_replen_2['mot']==mot]['weekday'].unique().tolist(),rotation=45)
    plt.show()

    # 执行方差分析
    f_stat, p_value = f_oneway(*data_list)

    # 输出结果
    print("F统计量:", f_stat)
    print("p值:", p_value)

在这里插入图片描述

F统计量: 127.26212162797701
p值: 4.906400437665232e-156

在这里插入图片描述

F统计量: 326.9319114756572
p值: 0.0

在这里插入图片描述

F统计量: 52.61132203829418
p值: 1.6153144700352586e-42
group_mot_climate_pu_atd = df_replen_2.groupby(['mot','Week']).agg({'lt_pu_atd':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
group_mot_climate_pu_atd.columns = ['mot','holiday_count','std','count','mean','quantile_5','quantile_9','quantile_1']
group_mot_climate_pu_atd
motholiday_countstdcountmeanquantile_5quantile_9quantile_1
0AIR星期一1.547858165441.8962162.04.00.0
1AIR星期三1.566505151212.0171952.04.00.0
2AIR星期二1.751875176812.0236982.04.00.0
3AIR星期五2.986730123852.4269682.06.00.0
group_mot_climate_pu_atd = df_replen_2.groupby(['mot','holiday_count']).agg({'lt_pu_atd':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
group_mot_climate_pu_atd.columns = ['mot','holiday_count','std','count','mean','quantile_5','quantile_9','quantile_1']
group_mot_climate_pu_atd
motholiday_countstdcountmeanquantile_5quantile_9quantile_1
0AIR^<= 7 hldys1.94587817614.0403184.07.02.0
1AIR^== 0 hldys1.994225466452.0121991.05.00.0
2AIR^== 1 hldys2.298573243031.8701392.04.00.0
3AIR^== 2 hldys1.453881173302.5364112.04.01.0
4SEA^<= 7 hldys2.1249204435.3160276.07.02.0
group_mot_climate_pu_atd = df_replen_2.groupby(['mot','climate_count']).agg({'lt_pu_atd':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
group_mot_climate_pu_atd.columns = ['mot','climate_count','std','count','mean','quantile_5','quantile_9','quantile_1']
group_mot_climate_pu_atd
motclimate_countstdcountmeanquantile_5quantile_9quantile_1
0AIR^<= 7 abnr1.18756534951.6148781.03.00.0
1AIR^== 0 abnr2.271866621672.2805512.05.00.0
2AIR^== 1 abnr1.276714121951.7785982.03.00.0
3AIR^== 2 abnr1.197433121821.7461012.03.00.0
group_mot_climate_pu_atd = df_replen_2.groupby(['mot','climate_count','holiday_count']).agg({'lt_pu_atd':['std','count','mean',lambda x:x.quantile(0.5),lambda x:x.quantile(0.9),lambda x:x.quantile(0.1)]}).reset_index()
group_mot_climate_pu_atd.columns = ['mot','climate_count','holiday_count','std','count','mean','quantile_5','quantile_9','quantile_1']
group_mot_climate_pu_atd.sort_values('mean',ascending=False)
motclimate_countholiday_countstdcountmeanquantile_5quantile_9quantile_1
17SEA^== 0 abnr^<= 7 hldys1.8304522726.0000007.07.02.2
df_replen_2['ts_pu'] = pd.to_datetime((df_replen_2['ts_pu']))
df_replen_open['ts_pu'] = pd.to_datetime((df_replen_open['ts_pu']))
df_replen_2['ts_pu_hour'] = df_replen_2['ts_pu'].dt.hour
df_replen_open['ts_pu_hour'] = df_replen_open['ts_pu'].dt.hour
df_replen_2['dayofweek'] = df_replen_2['ts_pu'].dt.dayofweek
df_replen_open['dayofweek'] = df_replen_open['ts_pu'].dt.dayofweek
for mot in df_replen_2['geo'].unique().tolist():
    plt.figure(figsize=(10, 6))
    sns.heatmap(data=df_replen_2[(df_replen_2['geo']==mot)][['lt_pu_pod','lt_pu_atd','ts_pu_hour','dayofweek']].corr(), cmap='coolwarm', annot=True, fmt=".2f", cbar=True)
    plt.title("Correlation between dayofweek,ts_pu_hour and lt_pu_pod lt_pu_atd")
    plt.xlabel("{0}".format(mot))
    plt.ylabel("country")
    plt.xticks(rotation=45)
    plt.show()

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/546432.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

chatgpt赋能Python-python3下载numpy包

Python3 下载numpy包教程 如果你是一名Python开发者&#xff0c;那你一定不会陌生于NumPy。NumPy是Python中的一个科学计算库&#xff0c;它主要用来处理数组和矩阵运算。本文将会教你如何在Python3中下载NumPy库。 步骤一&#xff1a;确认你已经安装了pip 如果你使用的是Py…

chatgpt赋能Python-python3__2__3

Python323 - 一个强大的编程工具 介绍 Python323 是一种高级编程语言&#xff0c;最初由 Guido van Rossum 在 1989 年创建。Python 3.2.3 是 Python 3 的其中一个发行版&#xff0c;它拥有很多新特性和改进。Python323 可以运行在多种操作系统上&#xff0c;包括 Windows、L…

redis哨兵监控leader和master选举原理

当一个主从配置中的master失效后&#xff0c;sentinel可以选举出一个新的master,用于自动接替原master的工作&#xff0c;主从配置中的其他redis服务器自动指向新的master同步数据。是如何具体做的呢&#xff0c;主要有以下4步。 一般建议sentinel 采取奇数台. 1.SDown 主观下…

Day43【动态规划】1049.最后一块石头的重量 II、494.目标和、474.一和零

1049.最后一块石头的重量 II 力扣题目链接/文章讲解 视频讲解 还是需要转化为 0-1 背包问题&#xff1a;物品装入背包&#xff0c;求装入的最大价值&#xff08;每个物品至多装入一次&#xff09; 要把01背包问题套到本题上来&#xff0c;需要确定 背包容量物品价值物品重…

分布式消息中间件RocketMQ的应用

RocketMQ 应用 所有代码同步至GitCode&#xff1a;https://gitcode.net/ruozhuliufeng/test-rocketmq.git 普通消息 消息发送分类 ​ Producer对于消息的发送方式也有多种选择&#xff0c;不同的方式会产生不同的系统效果。 同步发送消息 ​ 同步发送消息是指&#xff0c;P…

Win11或Win10重置电脑提示“找不到恢复环境”

想要重置电脑缺提示找不到恢复环境 查看是否开启功能 按住“winx”选A管理员运行终端&#xff0c;输入reagentc /info。 如果信息结果如下&#xff1a; Windows RE 状态: DisabledWindows RE 位置:引导配置数据(BCD)标识符: cedd8faa-707a-11ed-ad72-a8056da9f4d6…

头歌计算机组成原理实验—运算器设计(3)第3关:4位快速加法器设计

第3关&#xff1a;4位快速加法器设计 实验目的 帮助学生掌握快速加法器中先行进位的原理&#xff0c;能利用相关知识设计4位先行进位电路&#xff0c;并利用设计的4位先行进位电路构造4位快速加法器&#xff0c;能分析对应电路的时间延迟。 视频讲解 实验内容 利用前一步设…

Learning C++ No.23【红黑树封装set和map】

引言 北京时间&#xff1a;2023/5/17/22:19&#xff0c;不知道是以前学的不够扎实&#xff0c;还是很久没有学习相关知识&#xff0c;对有的知识可以说是遗忘了许多&#xff0c;以该篇博客有关知识为例&#xff0c;我发现我对迭代器和模板的有关知识的理解还不够透彻&#xff…

音视频源码调试前准备vs2019+qt5.15.2搭建可调试环境

安装vs2019qt,并且在windows环境上安装ffmpeg&#xff0c;尝试使用qtcdb进行调试&#xff0c;尝试使用vs2019加载qt的程序。 安装VS20195.12.2qt环境&#xff0c;并进行测试。 1&#xff1a;安装Visual Studio 2019, a.从官网下载&#xff0c;或者vs2019社区版本下载地址 ht…

SNAP软件处理Sentinel-2 L2A数据为hdr或者tif文件

1.打开Sen2Cor插件处理好的或者下载好的L2A文件 若不知道如何将下载的L1C数据处理为L2A级数据可查看该篇博文 Sentinel-2数据下载及处理_dropoutgirl的博客-CSDN博客 在Bands文件夹下少了B10波段栅格文件: 这主要是因为波段10是卷云波段&#xff0c;需要的大气顶部&#xff0…

顺序表之线性表(难度:✨)

1.线性表 线性表呈现出一条线性&#xff0c;用指针把一块一块的内存连接起来。 其余还有树型结构&#xff0c;哈希结构&#xff0c;图结构。 线性表分为&#xff1a; 顺序表链表栈队列字符串 1.2顺序表 顺序表就是数组&#xff0c;但在数组的基础上&#xff0c;从头开始存。…

地下车库CO传感器报警系统

前言 在现代城市中&#xff0c;地下车库已经成为了不可或缺的交通设施。然而&#xff0c;在地下车库中&#xff0c;由于车辆尾气等因素&#xff0c;很容易出现CO中毒的风险&#xff0c;给车库内的人员带来威胁。本文将对地下车库CO传感器报警系统进行介绍和分析&#xff0c;包…

21级计科专业计算机组成原理实验考试(体验)

在使用VC6.0软件时&#xff0c;为了进入调试模式&#xff0c;需要先点击【Build】&#xff0c;再点击&#xff08; &#xff09; A. BuildExecute B. Go C. Execute D. Compile 在使用VC6.0软件进入调试模式后&#xff0c;点击【View】→【Debug Windows】后的&#xff08; &…

Shell脚本常见用法列举

前言 最近在复习shell脚本的相关知识&#xff0c;本文列举了一些在shell脚本中用得到的一些基础语法。 1&#xff1a;打印常见内部变量和环境变量值 shell中常用变量介绍 $0脚本名$n第n个参数&#xff0c;n1,2,3...$*所有参数列表&#xff08;视为一个整体&#xff0c;不包…

chatgpt赋能Python-python3人脸识别

人脸识别的python3应用&#xff1a;一步步实现高精度的面部识别 Python3作为一种高效的编程语言&#xff0c;具有广泛的应用场景。近年来&#xff0c;人脸识别技术在安防、金融、医疗等领域中逐渐普及&#xff0c;运用Python3进行人脸识别具有巨大的潜力。本文将介绍如何使用P…

React学习笔记四-state

此文章是本人在学习React的时候&#xff0c;写下的学习笔记&#xff0c;在此纪录和分享。此为第四篇&#xff0c;主要介绍react中的state。 1.state&#xff08;状态&#xff09; 1.1state简介 存在state(状态)的组件称为复杂组件&#xff0c;反之称为简单组件。 何为状态呢…

TCL表达式

目录 操作数 运算符和优先级 数学函数 操作数 TCL 表达式的操作数通常是整数或实数。整数一般是十进制的&#xff0c; 但如果整数的第一个字符是 0(zero)&#xff0c;那么 TCL 将把这个整数看作八进制的&#xff0c;如果前两个字符是 0x 则这个整数被看作是十 六进制的。TC…

I2C项目问题总结

1、项目里面用到哪些接口&#xff1f;都是怎么用的&#xff1f; 项目里面用到了rkv_i2c_if、lvc_i2c_if、lvc_apb_if。rkv_i2c_if用来将DUT内部的intr中断信号、debug信号、ic_en使能信号、i2c和apb的时钟复位信号引出&#xff0c;在接口中声明了一个大位宽信号用来表示intr中…

分布式消息中间件RocketMQ的工作原理

RocketMQ 工作原理 消息的生产 消息的生产过程 ​ Producer可以将消息写入到某Broker中的某Queue中&#xff0c;其经历了如下过程&#xff1a; Producer发送消息之前&#xff0c;会先向NameServer发出获取消息Topic的路由信息的请求NameServer返回该Topic的路由表及Broker列…

kubernetes yaml文件|--dry-run导出yaml文件

kubernetes yaml文件|--dry-run导出yaml文件 YAML 语法格式&#xff1a;二 查看 api 资源版本标签三 写一个nignx.yaml文件demo四、编写service服务的资源清单详解k8s中的port五 用–dry-run命令生成yaml资源清单六 将现有的资源生成模板导出写yaml太累怎么办&#xff1f; YAML…