Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

第 12 章 Sklearn

目录

12.1. 生成回归样本数据
12.2. 鸢尾花数据集

12.1. 生成回归样本数据



n_samples:样本数
n_features:特征数(自变量个数)
n_informative:参与建模特征数
n_targets:因变量个数
noise:噪音
bias:偏差(截距)
coef:是否输出coef标识
random_state:随机状态若为固定值则每次产生的数据都一样,相当于随机种子

		
from sklearn import datasets
import matplotlib.pyplot as plt

x,y=datasets.make_regression(n_samples=100,n_features=2,n_targets=2,noise=2)

plt.figure()
plt.scatter(x,y)
plt.show()
		
		
		

通过 NumPy 用一次多项式拟合,相当于线性拟合

		
from sklearn.datasets import make_regression
import matplotlib.pyplot as plt
import numpy as np

x, y = make_regression(n_samples=10, n_features=1, n_targets=1, noise=1.5, random_state=1)

plt.figure()
plt.scatter(x, y);

z1 = np.polyfit(x.reshape(10), y, 1)
p1 = np.poly1d(z1)
print(z1)
print(p1)

y1 = z1[0] * x + z1[1]
plt.plot(x, y1, c='green')
plt.show()