forked from jimin61445/DataScience
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStandardScaler.py
More file actions
34 lines (28 loc) · 1.11 KB
/
StandardScaler.py
File metadata and controls
34 lines (28 loc) · 1.11 KB
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
32
33
34
import pandas as pd
from sklearn.preprocessing import StandardScaler
import seaborn as sns
import matplotlib.pyplot as plt
# 폰트 설정
plt.rcParams['font.family'] = 'Malgun Gothic'
plt.rcParams['axes.unicode_minus'] = False
def scale_csv(csv_file):
# CSV 파일 읽기
data = pd.read_csv(csv_file , encoding="cp949")
# 데이터 프레임에서 숫자형 열 선택
numeric_cols = data.iloc[:, 7:].columns
# StandardScaler 객체 생성
scaler = StandardScaler()
# 선택된 열을 표준화
data[numeric_cols] = scaler.fit_transform(data[numeric_cols])
return data
# 스케일링된 데이터프레임 생성
scaled_data = scale_csv("test_dataset/after_handling_nan.csv.csv")
# 스케일된 데이터를 새로운 CSV 파일로 저장
scaled_data.to_csv("test_dataset/scaled_data_standard.csv", index=False, encoding='cp949')
# 상관 행렬 계산
correlation_matrix = scaled_data.iloc[:, 7:].corr()
# 히트맵 그리기
plt.figure(figsize=(12, 10))
sns.heatmap(correlation_matrix, annot=True, cmap='coolwarm', fmt=".2f", linewidths=0.5)
plt.title('상관 관계 히트맵')
plt.show()