๋ฐ์ํ
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 |
Tags
- ์ง ๊ฐ ์์ธก ๋ถ์
- ์ฐธ์กฐ ๋ณ์
- np.zeros_like
- ์๋ฐ
- PYTHON
- matplotlib
- sql
- java
- ํ๋ก๊ทธ๋๋จธ์ค
- 2BPerfect
- ์ต์
- ๋ฐฑ์ค
- Do it
- ์ ํ ํฌ ํ์ด์ฌ
- ๋ธ๋ผ์ฐ์ ์คํ
- Do_it
- dacon
- ํ์ ๋ณ์
- Extended Slices
- ํฉํ ๋ฆฌ์ผ ์ง๋ฒ
- ๋ค์ต์คํธ๋ผ ์๊ณ ๋ฆฌ์ฆ
- MacOS
- mysql
- ์์ด
- BFS
- ์ด์ง์ ๋ณํ
- DFS
- ์ด๊ฒ์ด ์ทจ์ ์ ์ํ ์ฝ๋ฉํ ์คํธ๋ค
- ๋ฐ์ค๊ทธ๋ํ
- jdbc
Archives
- Today
- Total
๐ฆ ๊ณต๋ฃก์ด ๋์!
์ง ๊ฐ ์์ธก ๋ถ์...3 ๋ณธ๋ฌธ
์๊ด๊ด๊ณ ์๊ฐํ
1์ฅ ๋ถ๋ถ
# ๋จผ์ ์๊ด๊ณ์ ๊ณ์ฐ์ ์ํด ํ
์คํธ ํ์์ ๋ฐ์ดํฐ๋ฅผ ์ซ์๋ก ๋ณํํด์ค.
from sklearn.preprocessing import LabelEncoder
# ๋ฅ ๋ณต์ฌ
corr_df = data.copy()
corr_df[corr_df.columns[corr_df.dtypes=='O']] = corr_df[corr_df.columns[corr_df.dtypes=='O']].astype(str).apply(LabelEncoder().fit_transform)
corr_df['Exter Qual'].unique()
## ์๊ด๊ด๊ณ๋ฅผ ๋ถ์ํด๋ณด๋ฉด ๋ฐ๋น๋ก์ ์์๊ฐ ๋ง์
#์ด ๋ถ๋ถ์ sklearn์ ํตํด ์ ๋๋ก ๋ ์์นํ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์๋ค๊ณ ์๊ฐํจ.
corr_df.info()
๊ฐ์ ๋ ์ฝ๋
# ๊ทธ๋์ ๋ช
๋ชฉํ ๋ฐ์ดํฐ๋ค์ ํ์
ํ๊ณ
data['Exter Qual'].unique()
data.info()
# ๊ทธ ๊ฐ๋ค์ ํ๋ํ๋ ๋ฐ๊ฟ์ค ๋คํํ ๊ฐ์ ์ฒ๋๋ก ๊ณ์ฐ์ด ๋๊ณ ์์ด์ ๋ฐ๊พธ๊ธฐ๊ฐ ์ฌ์ ์
data2=data.copy()
for i in data[data.columns[data.dtypes=='O']]:
print(i)
data2 = data2.replace({f'{i}' : {"Po":0, "Fa" : 1, "TA" : 2, "Gd" : 3, "Ex" : 4}})
data2.info()
์์ ์ heatmap
#์๊ด๊ด๊ณ ๋ถ์๋ ์ด๊ฒ ๋ฐ์ดํฐ ๋ถ์ํ๋๋ฐ์ ์ ์ผ ์ ์ฉํ ์๊ฐํ๊ฐ ์๋๊ฐ ์ถ๋ค
plt.figure(figsize=(15,10))
heat_table = corr_df.corr()
mask = np.zeros_like(heat_table)
mask[np.triu_indices_from(mask)] = True
heatmap_ax = sns.heatmap(heat_table, annot=True, mask = mask, cmap='coolwarm')
heatmap_ax.set_xticklabels(heatmap_ax.get_xticklabels(), fontsize=15, rotation=45)
# ๊ธ์ ๊ธฐ์ธ์ด๊ธฐ ๋ฐ ํฐํธ์ฌ์ด์ฆ ๊ฐ๋๋ ๋ฐ์๊ณ ๋ฐฉํฅ
heatmap_ax.set_yticklabels(heatmap_ax.get_yticklabels(), fontsize=15)
plt.title('correlation between features', fontsize=40)
plt.show()
# target๊ณผ ๋์ ์๊ด๊ด๊ณ๋ฅผ ๊ฐ์ง๋ ๊ฒ๋ค
heat_table.loc[:,'target'].sort_values().tail(7)
์์ ํ heatmap
plt.figure(figsize=(15,10))
heat_table2 =data2.corr()# ํ๋ค์ค ์๊ด๊ด๊ณ
# ์ผ๊ฐํ ๋ง์คํฌ๋ฅผ ๋ง๋ ๋ค(์ ์ชฝ ์ผ๊ฐํ์ True, ์๋ ์ผ๊ฐํ์ False)
mask = np.zeros_like(heat_table2) #numpy heat_table๊ณผ shape๋์ผํ 0์ผ๋ก ์ฑ์์งํ๋ ฌ
mask[np.triu_indices_from(mask)] = True
# heatmap
heatmap_ax = sns.heatmap(heat_table2, annot=True, mask = mask, cmap='coolwarm')
# x์ถ ์ธํ
heatmap_ax.set_xticklabels(heatmap_ax.get_xticklabels(), fontsize=15, rotation=45)
# ๊ธ์ ๊ธฐ์ธ์ด๊ธฐ ๋ฐ ํฐํธ์ฌ์ด์ฆ ๊ฐ๋๋ ๋ฐ์๊ณ ๋ฐฉํฅ
# y์ถ ์ธํ
heatmap_ax.set_yticklabels(heatmap_ax.get_yticklabels(), fontsize=15)
plt.title('correlation between features', fontsize=40)
plt.show()
# target๊ณผ ๋์ ์๊ด๊ด๊ณ๋ฅผ ๊ฐ์ง๋ ๊ฒ๋ค
heat_table2.loc[:,'target'].sort_values().tail(7)
sklearn์ผ๋ก ํ ๊ฒ๊ณผ๋ ์ฐจ์ด๊ฐ ์ข ์๋ค.
์ญ์ ์์ง์ ์ธ๊ณต์ง๋ฅ๋ณด๋ค๋ ์ฌ๋์ด๋ค.
๋ฐ์ํ
'Data > Dacon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์ง ๊ฐ ์์ธก ๋ถ์...2 (0) | 2022.02.08 |
---|---|
์ง ๊ฐ ์์ธก ๋ถ์...1 (0) | 2022.02.03 |
Dacon ์์ธ ํ์ง ๊ฒฝ์ง๋ํ...3 (0) | 2021.12.10 |
Dacon ์์ธํ์ง ๊ฒฝ์ง๋ํ...2 (0) | 2021.12.07 |
Dacon ์์ธ ํ์ง ๊ฒฝ์ง๋ํ (0) | 2021.12.06 |
Comments