使用感知机对iris数据集中的前两维特征构成的数据点分类
import numpy as np
import pandas as pd
from sklearn.datasets import load_iris
import matplotlib.pyplot as plt
iris = load_iris()
df = pd.DataFrame(iris.data, columns=iris.feature_names)
df['label'] = iris.target
df.columns = [
'sepal length', 'sepal width', 'petal length', 'petal width', 'label'
]
df.head()
![数据集详情](https://i-blog.csdnimg.cn/blog_migrate/7d1bfa7f755f9db174611bb8964a448b.png)
plt.scatter(df[:50]['sepal length'], df[:50]['sepal width'], label='0')
plt.scatter(df[50:100]['sepal length'], df[50:100]['sepal width'], label='1')
plt.xlabel('sepal length')
plt.ylabel('sepal width')
plt.legend()
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/145e26220b0b220329cfc30292296cb7.png)
data = df.iloc[: