import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
# 读取数据
data = pd.read_csv('data')
x = data.drop(['name','age','armTemp','enviTemp'],axis = 1)
# 选择要分析的特征
target_feature = ''
other_features = x.drop(columns=target_feature)
other_features = other_features.columns.tolist()
type(other_features)
# 绘制散点图
for feature in other_features:
plt.scatter(x[feature], x[target_feature], label=feature)
plt.xlabel('Other Features')
plt.ylabel('Target Feature')
plt.legend()
plt.show()
# 计算相关系数
correlation_matrix = data[other_features + [target_feature]].corr()
# print(correlation_matrix)
target_correlation = correlation_matrix.loc[target_feature, other_features]
print(target_correlation)
type(target_correlation)
target_correlation.abs().sort_values(ascending=False)
查看数据特征之间的相关性
最新推荐文章于 2025-03-03 14:00:53 发布