Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
Tags
- hierarchical_clustering
- elbow method
- DataAccess
- 반복문
- Dictionary
- 최솟값
- dendrogram
- Machine Learning
- wcss
- 덴드로그램
- IN
- pandas
- Python
- DataFrame
- function
- string
- list
- 분류 결과표
- analizer
- matplotlib
- sklearn
- data
- append()
- del
- numpy
- len()
- count()
- 최댓값
- insert()
- nan
Archives
- Today
- Total
개발공부
[Python] Matplotlib 여러 개의 변수 시각화 방법 (Scatter, seaborn.Regplot, Heat Map), 상관계수 (dataframe.corr()) 본문
Python/Matplotlib
[Python] Matplotlib 여러 개의 변수 시각화 방법 (Scatter, seaborn.Regplot, Heat Map), 상관계수 (dataframe.corr())
mscha 2022. 5. 4. 15:09import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sb
아래는 차량의 메이커, 모델, 년도, 분류, 연비 등등을 나타낸 데이터 프레임이다.
두 컬럼간의 관계를 표현하는 차트
1. matplotlib 의 scatter 사용
displ과 comb의 상관관계를 표현하라
plt.scatter(data = df, x = 'displ', y = 'comb')
plt.title('Displ Vs Comb')
plt.xlabel('Displacement (L)')
plt.ylabel('Combined Fuel Etf (mpg)')
plt.show()
2. seaborn 의 regplot 을 이용하는 방법
reg 의 뜻은 ?
- regression (회귀) : 데이터에 fitting 한다는 의미
sb.regplot(data = df, x = 'displ', y = 'comb')
plt.title('Displ Vs Comb')
plt.xlabel('Displacement (L)')
plt.ylabel('Combined Fuel Etf (mpg)')
plt.show()
3. seaborn 의 pairplot 을 이용하는 방법
sb.pairplot(data = df, vars= ['displ', 'comb'])
plt.show()
상관계수 구하기
df[['displ', 'comb']].corr()
+1의 경우 완벽한 양의 선형 상관 관계,
-1의 경우 완벽한 음의 상관관계,
0의 경우 선형 상관관계를 갖지 않는다.
displ 과 comb는 음의 상관관계 (반비례) 관계임을 알 수 있다.
4. matplotlib의 hist2d(히트맵 Heatmap) 을 이용하는 방법
스케터는, 여러 데이터가 한군데 뭉치면 보기가 힘들다는 단점이 있다.
히트맵을 이용하면 화면에 밀도를 표시해주어서 이를 눈이 보기 편하게 표현할 수 있다.
plt.hist2d(data = df, x = 'displ', y = 'comb', cmin = 0.5, cmap = 'viridis_r',
bins = 20)
plt.colorbar()
plt.title('Displ Vs Comb')
plt.xlabel('Displacement (L)')
plt.ylabel('Combined Fuel Etf (mpg)')
plt.show()
'Python > Matplotlib' 카테고리의 다른 글
[Python] Matplotlib 여러개의 차트를 그릴 수 있는 Subplot (0) | 2022.05.04 |
---|---|
[Python] Matplotlib Histogram(히스토그램) (0) | 2022.05.03 |
[Python] Matplotlib Plot(플롯), Bar(바), Pie(파이) Chart (0) | 2022.05.03 |