📜  如何在Python中使用 Pandas 绘制安德鲁斯曲线?

📅  最后修改于: 2022-05-13 01:55:38.745000             🧑  作者: Mango

如何在Python中使用 Pandas 绘制安德鲁斯曲线?

安德鲁斯曲线用于通过将每个观察映射到一个函数来可视化高维数据。它保留了均值、距离和方差。它由公式给出:

可以使用绘图的andrews_curves()方法在图形上绘制安德鲁斯曲线 模块。此函数生成 Andrews 曲线的 matplotlib 图,用于可视化多变量数据的集群。

示例 1:在以下示例中,数据框由 CSV 文件制成,数据框用于绘制 andrews_curves。使用的 CSV 文件在这里。

Python3
# importing various package
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
  
# making data frame from csv file
df = pd.read_csv(
    'C:\\Users\\digital india\\Desktop\\pand.csv'
)
  
# Creating Andrews curves
x = pd.plotting.andrews_curves(df, 'animal')
  
# ploting the Curve
x.plot()
  
# Display
plt.show()


Python3
# importing various package
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
  
# making data frame from csv file
df = pd.read_csv(
    'https://raw.github.com/pandas-dev/'
    'pandas/master/pandas/tests/io/data/csv/iris.csv'
)
  
# Creating Andrews curves
x = pd.plotting.andrews_curves(df, 'Name')
  
# ploting the Curve
x.plot()
  
# Display
plt.show()


输出:

示例 2:

Python3

# importing various package
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
  
# making data frame from csv file
df = pd.read_csv(
    'https://raw.github.com/pandas-dev/'
    'pandas/master/pandas/tests/io/data/csv/iris.csv'
)
  
# Creating Andrews curves
x = pd.plotting.andrews_curves(df, 'Name')
  
# ploting the Curve
x.plot()
  
# Display
plt.show()

输出: