본문 바로가기

Code/Phyton

Parallel coordinate plots / Andrews curve /

평행좌표그림 (Parallel coordinate plots)

입력 필드 X만큼 Y축을 만들고 동일한 행에 있는 값을 선으로 연결하여 그립니다.

 

 

from sklearn.datasets import load_iris
from pandas.tools.plotting import parallel_coordinates
	
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
	
# Look pretty...
matplotlib.style.use('ggplot')
# If the above line throws an error, use plt.style.use('ggplot') instead
	
# Load up SKLearn's Iris Dataset into a Pandas Dataframe
data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names) 
	
df['target_names'] = [data.target_names[i] for i in data.target]
	
# Parallel Coordinates Start Here:
plt.figure()
parallel_coordinates(df, 'target_names')
plt.show()


Andrews curve

 

from sklearn.datasets import load_iris
from pandas.tools.plotting import andrews_curves
	
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib
	
# Look pretty...
matplotlib.style.use('ggplot')
# If the above line throws an error, use plt.style.use('ggplot') instead
	
# Load up SKLearn's Iris Dataset into a Pandas Dataframe
data = load_iris()
df = pd.DataFrame(data.data, columns=data.feature_names)
df['target_names'] = [data.target_names[i] for i in data.target]
	
# Andrews Curves Start Here:
plt.figure()
andrews_curves(df, 'target_names')
plt.show()