【问题标题】:Correlation for complete dataset without any nan values is providing nan没有任何 nan 值的完整数据集的相关性提供 nan
【发布时间】:2021-03-20 14:24:14
【问题描述】:

没有任何 nan 值的完整数据集的相关性提供 nan。我已将所有分类列标记为数字。

请检查下面的代码

train_data.dypes

输出是:

Order_Ref_Number                 int64
Product_Ref_ID                   int64
Size                             int64
Color_Code                       int64
Product_Category_Reference       int64
Cost_to_Customer(USD)          float64
Customer_ID                      int64
Gender                           int64
Customer_BirthDate               int64
Customer_Location                int64
Order_Placed_AT_day              int64
Order_Placed_AT_month            int64
Order_Placed_AT_year             int64
Order_Delivered_Date_day         int64
Order_Delivered_Date_month       int64
Order_Delivered_Date_year        int64
Customer_Joining_Date_day        int64
Customer_Joining_Date_month      int64
Customer_Joining_Date_year       int64
Order_Repeat_Chance              int64
dtype: object

后跟代码:

correlation = train_data.corr()
print(correlation['Order_Repeat_Chance'].sort_values(ascending = False), '\n')

输出是:

Order_Repeat_Chance            1.000000
Cost_to_Customer(USD)          0.142347
Order_Ref_Number               0.061362
Order_Placed_AT_month          0.060764
Product_Ref_ID                 0.055347
Customer_BirthDate             0.050837
Order_Delivered_Date_month     0.040939
Product_Category_Reference     0.025365
Order_Delivered_Date_year      0.022811
Order_Delivered_Date_day       0.015046
Gender                         0.007147
Customer_ID                    0.002988
Customer_Location              0.002294
Customer_Joining_Date_day     -0.000358
Order_Placed_AT_day           -0.011442
Customer_Joining_Date_month   -0.021122
Color_Code                    -0.022827
Customer_Joining_Date_year    -0.024684
Size                          -0.035805
Order_Placed_AT_year                NaN
Name: Order_Repeat_Chance, dtype: float64

【问题讨论】:

    标签: python python-3.x pandas dataframe correlation


    【解决方案1】:

    没有看到你的train_data 很难说。但很可能Order_Placed_AT_year 中的所有数字都相同?因为那时corr 是NaN:

    import pandas as pd
    df = pd.DataFrame({'x':[1,2,3],'y':[1,1,1]})
    df.corr()
    

    给予

    
        x   y
    x   1.0 NaN
    y   NaN NaN
    

    之所以如此,是因为恒定时间序列的std0,在计算corr 时除以它

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2020-11-18
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多