【问题标题】:Unclear terms about Data visualization关于数据可视化的不清楚的术语
【发布时间】:2021-11-15 11:06:53
【问题描述】:

我有一个关于客户数据的 CSV 文件,我将其转换为 JSON Dict 类型,您可以在下面输入单个虚幻人的数据。

{
"First Name": "Jonathan",
"Last Name": "Thomas",
"Marital Status": "married or civil partner",
"Sex": "Male",
"Age (Years)": 46,
"Retired": true,
"Distance Commuted to Work (miles)": 13.72,
"Employer Company": "Begum-Williams",
"Dependants": 1,
"Yearly Salary (\u00c2\u00a3)": 54016,
"Yearly Pension (\u00c2\u00a3)": 0,
"Address Street": {
  "Address Street": "00 Wheeler wells",
  "Address City": "Chapmanton",
  "Address Postcode": "L2 7BT"
},
"Credit Card Number": {
  "Credit Card Number": "4529436854129855",
  "Credit Card Start Date": "08/12",
  "Credit Card Expiry Date": "11/26",
  "Credit Card CVV": 583,
  "Bank IBAN": "GB37UMCO54540228728019"
},
"Vehicle Make": {
  "Vehicle Make": "Nissan",
  "Vehicle Model": "ATS",
  "Vehicle Year": 1996,
  "Vehicle Type": "Coupe"
}

我想用 seaborn 可视化数据,我的任务就在下面:

  1. 执行以下数据属性的单变量图: a) 年龄,计算 bin_width 为 5 需要多少个 bin

  2. 使用以下数据属性执行多元绘图

您能否为我解释一下“单变量图”、“多变量图”以及最后“bin_width 为 5 需要多少个 bin”术语?

我对这些术语感到困惑。谢谢

【问题讨论】:

    标签: python json csv seaborn data-visualization


    【解决方案1】:

    "Univariate" 表示“只涉及一个变量”。例如,只涉及年龄。 “多变量”只是意味着“涉及多个变量”。

    要计算给定 bin 宽度的 bin 数量,您可以从最大值中减去可能的最小值,除以 bin 宽度,然后加 1。Seaborn 的 histplot 允许您直接设置 binwidth 并确实为您计算。

    这是一个使用泰坦尼克数据集的例子:

    import seaborn as sns
    
    sns.set()
    titanic = sns.load_dataset('titanic')
    # sns.histplot(data=titanic, x='age', bins=int(titanic.age.max()-titanic.age.min())//5+1 )
    sns.histplot(data=titanic, x='age', binwidth=5, color='crimson')
    

    使用 2 个变量(“双变量”),您可以例如创建二维kdeplot。或scatterplot。更多变量可以用a 3rd dimension、颜色(在Seaborn 中称为hue)、大小和/或标记样式表示。 选择哪种类型的绘图在很大程度上取决于您的数据以及您希望与绘图交流的内容。

    这是一个示例,使用二维作为scatterplot,色调作为第三。右侧显示了一个 2D kdeplot

    import matplotlib.pyplot as plt
    import seaborn as sns
    
    sns.set()
    titanic = sns.load_dataset('titanic')
    
    fig, (ax1, ax2) = plt.subplots(ncols=2, figsize=(14, 4))
    sns.scatterplot(data=titanic, x='age', y='fare', hue='alive', ax=ax1)
    sns.kdeplot(data=titanic, x='age', y='fare', fill=True, ax=ax2)
    plt.tight_layout()
    plt.show()
    

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-23
    • 2015-12-07
    • 1970-01-01
    • 2011-02-06
    • 2022-07-25
    • 1970-01-01
    • 1970-01-01
    • 2010-11-18
    相关资源
    最近更新 更多