【机器学习】监督学习算法 2.3.1 二分类、回归算法、威斯康辛乳腺癌、波士顿房价

本文通过使用matplotlib和mglearn库对多个机器学习数据集进行可视化,包括锻造数据集和波浪数据集的二维散点图及目标值分布,乳腺癌数据集的关键特征和样本类别分布,以及波士顿房价数据集的规模。同时,展示了如何加载并查看数据集的详细信息。
摘要由CSDN通过智能技术生成
import mglearn 
import matplotlib.pyplot as plt

x,y = mglearn.datasets.make_forge()

mglearn.discrete_scatter(x[:,0],x[:,1],y)
plt.legend(['Class 0','Class 1'],loc = 4)
plt.xlabel('first feature')
plt.ylabel('second feature')
print('x.shape:{}'.format(x.shape))
plt.show()
 
x.shape:(26, 2)

在这里插入图片描述

x,y = mglearn.datasets.make_wave(n_samples=40)
plt.plot(x,y,'o')
plt.ylim(-3,3)
plt.xlabel('feature')
plt.ylabel('target')
plt.show()

在这里插入图片描述
总程序

import mglearn 
import matplotlib.pyplot as plt
import numpy as np

x,y = mglearn.datasets.make_forge()

mglearn.discrete_scatter(x[:,0],x[:,1],y)
plt.legend(['Class 0','Class 1'],loc = 4)
plt.xlabel('first feature')
plt.ylabel('second feature')
print('x.shape:{}'.format(x.shape))
plt.show()
 
x,y = mglearn.datasets.make_wave(n_samples=40)
plt.plot(x,y,'o')
plt.ylim(-3,3)
plt.xlabel('feature')
plt.ylabel('target')
plt.show()

from sklearn.datasets import load_breast_cancer
cancer = load_breast_cancer()
print("cancer.keys():\n{}".format(cancer.keys()))
print('shape of cancer data:\n{}'.format(cancer.data.shape))
print('sample counts per class:\n{}'.format({n : v for n,v in zip(cancer.target_names,np.bincount(cancer.target))}))
print('feature names:\n{}'.format(cancer.feature_names))

from sklearn.datasets import load_boston
boston = load_boston()
print('data shape:\n{}'.format(boston.data.shape))

x,y = mglearn.datasets.load_extended_boston()
print('x.shape:{}'.format(x.shape))

x.shape:(26, 2)
cancer.keys():
dict_keys(['data', 'target', 'target_names', 'DESCR', 'feature_names'])
shape of cancer data:
(569, 30)
sample counts per class:
{'malignant': 212, 'benign': 357}
feature names:
['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' 'compactness error' 'concavity error'
 'concave points error' 'symmetry error' 'fractal dimension error'
 'worst radius' 'worst texture' 'worst perimeter' 'worst area'
 'worst smoothness' 'worst compactness' 'worst concavity'
 'worst concave points' 'worst symmetry' 'worst fractal dimension']
data shape:
(506, 13)
x.shape:(506, 104)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值