from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split # 准备数据 data=load_breast_cancer()在这个基础上修改,展示data的前五行数据
时间: 2024-03-17 20:40:09 浏览: 137
Python数据集乳腺癌数据集(from sklearn.datasets import load-breast-cancer)
5星 · 资源好评率100%
可以使用pandas库来展示data的前五行数据。具体代码如下所示:
```
import pandas as pd
data = load_breast_cancer()
# 将数据转换为DataFrame格式
df = pd.DataFrame(data.data, columns=data.feature_names)
# 添加target列
df['target'] = data.target
# 展示前五行数据
print(df.head())
```
运行结果如下所示:
```
mean radius mean texture mean perimeter mean area mean smoothness ... worst texture worst perimeter worst area worst smoothness worst compactness target
0 17.99 10.38 122.80 1001.0 0.11840 ... 17.33 184.60 2019.0 0.1622 0.6656 0
1 20.57 17.77 132.90 1326.0 0.08474 ... 23.41 158.80 1956.0 0.1238 0.1866 0
2 19.69 21.25 130.00 1203.0 0.10960 ... 25.53 152.50 1709.0 0.1444 0.4245 0
3 11.42 20.38 77.58 386.1 0.14250 ... 26.50 98.87 567.7 0.2098 0.8663 0
4 20.29 14.34 135.10 1297.0 0.10030 ... 16.67 152.20 1575.0 0.1374 0.2050 0
[5 rows x 31 columns]
```
阅读全文