使用UCI库乳腺癌数据集代码
时间: 2023-07-16 22:13:50 浏览: 191
乳腺癌分类器及数据样本验证(Python).docx
以下是使用UCI库乳腺癌数据集的Python代码示例:
```python
import pandas as pd
import numpy as np
from sklearn.datasets import load_breast_cancer
# 加载UCI乳腺癌数据集
data = load_breast_cancer()
# 将数据集转换为pandas DataFrame格式
df = pd.DataFrame(np.c_[data['data'], data['target']],
columns=np.append(data['feature_names'], ['target']))
# 打印数据集信息
print(df.info())
# 打印数据集前5行
print(df.head())
```
输出结果如下:
```
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 569 entries, 0 to 568
Data columns (total 31 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 mean radius 569 non-null float64
1 mean texture 569 non-null float64
2 mean perimeter 569 non-null float64
3 mean area 569 non-null float64
4 mean smoothness 569 non-null float64
5 mean compactness 569 non-null float64
6 mean concavity 569 non-null float64
7 mean concave points 569 non-null float64
8 mean symmetry 569 non-null float64
9 mean fractal dimension 569 non-null float64
10 radius error 569 non-null float64
11 texture error 569 non-null float64
12 perimeter error 569 non-null float64
13 area error 569 non-null float64
14 smoothness error 569 non-null float64
15 compactness error 569 non-null float64
16 concavity error 569 non-null float64
17 concave points error 569 non-null float64
18 symmetry error 569 non-null float64
19 fractal dimension error 569 non-null float64
20 worst radius 569 non-null float64
21 worst texture 569 non-null float64
22 worst perimeter 569 non-null float64
23 worst area 569 non-null float64
24 worst smoothness 569 non-null float64
25 worst compactness 569 non-null float64
26 worst concavity 569 non-null float64
27 worst concave points 569 non-null float64
28 worst symmetry 569 non-null float64
29 worst fractal dimension 569 non-null float64
30 target 569 non-null float64
dtypes: float64(31)
memory usage: 137.9 KB
None
mean radius mean texture mean perimeter mean area mean smoothness mean compactness mean concavity mean concave points mean symmetry mean fractal dimension radius error texture error perimeter error area error smoothness error compac...
0 17.99 10.38 122.80 1001.0 0.1184 0.2776 0.3001 0.14710 0.2419 0.07871 1.0950 0.9053 8.589 153.40000 0.006399 ...
1 20.57 17.77 132.90 1326.0 0.0847 0.0786 0.0869 0.07017 0.1812 0.05667 0.5435 0.7339 3.398 74.08000 0.005225 ...
2 19.69 21.25 130.00 1203.0 0.1096 0.1599 0.1974 0.12790 0.2069 0.05999 0.7456 0.7869 4.585 94.03000 0.006150 ...
3 11.42 20.38 77.58 386.1 0.1425 0.2839 0.2414 0.10520 0.2597 0.09744 0.4956 1.1560 3.445 27.23000 0.009110 ...
4 20.29 14.34 135.10 1297.0 0.1003 0.1328 0.1980 0.10430 0.1809 0.05883 0.7572 0.7813 5.438 94.44000 0.011490 ...
```
这里使用了sklearn库的load_breast_cancer函数来加载乳腺癌数据集,然后将其转换为pandas DataFrame格式,方便数据分析和处理。
阅读全文