python乳腺癌可视化
时间: 2023-06-29 12:17:59 浏览: 54
针对乳腺癌数据的可视化可以帮助我们更好地理解数据、发现规律和趋势,从而更好地做出决策和预测。下面是一个使用 Python 进行乳腺癌数据可视化的示例:
```python
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
# 读取数据
data = pd.read_csv('breast_cancer_data.csv')
# 数据预处理
data.drop('id', axis=1, inplace=True)
data['diagnosis'] = data['diagnosis'].map({'M': 1, 'B': 0})
# 绘制直方图
plt.figure(figsize=(10, 8))
sns.distplot(data[data['diagnosis'] == 0]['radius_mean'], color='green', label='Benign')
sns.distplot(data[data['diagnosis'] == 1]['radius_mean'], color='red', label='Malignant')
plt.title('Radius Mean Distribution by Diagnosis')
plt.legend()
plt.show()
# 绘制热力图
corr = data.corr()
plt.figure(figsize=(20, 20))
sns.heatmap(corr, annot=True, cmap='coolwarm')
plt.title('Correlation Matrix')
plt.show()
```
上述代码中,我们使用了 Seaborn 和 Matplotlib 库来绘制直方图和热力图。首先,我们读取了乳腺癌数据,并进行一些简单的处理。然后,我们使用 `sns.distplot` 函数绘制了一个直方图,用来展示恶性和良性乳腺癌患者的半径均值分布情况。接着,我们使用 `sns.heatmap` 函数绘制了一个热力图,展示不同特征之间的相关性。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)