## 2.1使用scikit-learn机器学习包的算法，对鸢尾花进行分类

```import matplotlib.pyplot as plt
X = iris.data
print(X.shape, X)
y = iris.target
print(y.shape, y)```

`matplotlib.pyplot.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None,`

vmax=None, alpha=None, linewidths=None, verts=None, edgecolors=None, hold=None, data=None, **kwargs)

```feature = 1
feature_other = 2
plt.scatter(X[0:50,feature], X[0:50,feature_other], color='red', marker='o', label='setosa') #前50个样本
plt.scatter(X[50:100,feature], X[50:100,feature_other], color='blue', marker='x', label='versicolor') #中间50个
plt.scatter(X[100:,feature], X[100:,feature_other],color='green', marker='+', label='Virginica') #后50个样本
plt.show()```

plt.show()显示散点图：

## 2.2 使用scikit-learn机器学习包的线性回归算法，选择一个特征对鸢尾花进行分类

`import numpy as np`

`from sklearn import linear_model`

`linear_model.LinearRegression(fit_intercept=True, normalize=False,copy_X=True, n_jobs=1)`

`linear.fit(X[:,:1],y)`

`print("线性回归 training score: ",linear.score(X[:,:1],y))`

```plt.scatter(X[:,:1],y)
plt.scatter(X[:,:1],np.dot(X[:,:1],linear.coef_)+linear.intercept_)
plt.plot(X[:,:1],np.dot(X[:,:1],linear.coef_)+linear.intercept_)
plt.show()```

## 2.3 使用scikit-learn机器学习包的线性回归算法，选择两个特征对鸢尾花进行分类

```for j in range(4):
if i<j:
x_slice = X[:,[i,j]]
predict_slice = predict_data[:,[i,j]]
features.append([i,j])
func_linear(x_slice,y,scores)
x_slice = X[:,[0,1,2,3]]
predict_slice = predict_data[:,[0,1,2,3]]
features.append([0,1,2,3])
func_linear(x_slice,y,scores)
print(features)
print(scores)
print(predict_results)```

## 2.4 使用scikit-learn机器学习包的线性回归算法，选择三个特征对鸢尾花进行分类；

```for j in range(4):
if i<j:
x_slice = X[:,[i,j]]
predict_slice = predict_data[:,[i,j]]
features.append([i,j])
func_linear(x_slice,y,scores)
for k in range(4):
if i<j and j<k:
x_slice = X[:,[i,j,k]]
predict_slice =predict_data[:,[i,j,k]]
features.append([i,j,k])
func_linear(x_slice,y,scores)```

2.5 结合上一个数据分析和可视化实验，根据对鸢尾花数据的特征两两对比可视化图，分析特征可视化对特征选择及相关分类计算结果的影响