# 예시 데이터 생성 np.random.seed(0) study_hours = np.random.rand(100) * 10 exam_scores = 3 * study_hours + np.random.randn(100) * 5 # 데이터프레임 생성 df = pd.DataFrame({'Study Hours': study_hours, 'Exam Scores': exam_scores}) # 피어슨 상관계수 계산 pearson_corr, _ = pearsonr(df['Study Hours'], df['Exam Scores']) print(f"피어슨 상관계수: {pearson_corr}") # 상관관계 히트맵 시각화 sns.heatmap(df.corr(), annot=True, cmap='coolwarm', vmin=-1, vmax=1) plt.title('pearson coefficient heatmap') plt.show()
from scipy.stats import spearmanr, kendalltau # 예시 데이터 생성 np.random.seed(0) customer_satisfaction = np.random.rand(100) repurchase_intent = 3 * customer_satisfaction + np.random.randn(100) * 0.5 # 데이터프레임 생성 df = pd.DataFrame({'Customer Satisfaction': customer_satisfaction, 'Repurchase Intent': repurchase_intent}) # 스피어만 상관계수 계산 spearman_corr, _ = spearmanr(df['Customer Satisfaction'], df['Repurchase Intent']) print(f"스피어만 상관계수: {spearman_corr}") # 켄달의 타우 상관계수 계산 kendall_corr, _ = kendalltau(df['Customer Satisfaction'], df['Repurchase Intent']) print(f"켄달의 타우 상관계수: {kendall_corr}") # 상관관계 히트맵 시각화 sns.heatmap(df.corr(method='spearman'), annot=True, cmap='coolwarm', vmin=-1, vmax=1) plt.title('spearman coefficient heatmap') plt.show()
import numpy as np from sklearn.metrics import mutual_info_score # 범주형 예제 데이터 X = np.array(['cat', 'dog', 'cat', 'cat', 'dog', 'dog', 'cat', 'dog', 'dog', 'cat']) Y = np.array(['high', 'low', 'high', 'high', 'low', 'low', 'high', 'low', 'low', 'high']) # 상호 정보량 계산 mi = mutual_info_score(X, Y) print(f"Mutual Information (categorical): {mi}")