from sklearn import datasets#引入数据集,sklearn包含众多数据集
from sklearn.model_selection import train_test_split#将数据分为测试集和训练集
from sklearn.neighbors import KNeighborsClassifier#利用邻近点方式训练数据
import matplotlib as mpl
import matplotlib.pyplot as plt
import numpy as np
###引入数据###
iris=datasets.load_iris()#引入iris鸢尾花数据,iris数据包含4个特征变量
# print(iris.keys())
# print(iris.DESCR)
iris_X=iris.data#特征变量
iris_y=iris.target#目标值
X_train,X_test,y_train,y_test=train_test_split(iris_X,iris_y,test_size=0.3)#利用train_test_split进行将训练集和测试集进行分开,test_size占30%
# print(y_train)#我们看到训练数据的特征值分为3类
# print(iris_X.shape)
# print(iris.feature_names)
# print(iris.target_names)
# print(iris_y)
print(iris_X)
X=iris.data[:,1:3]
print(X.shape)
# plt.scatter(X[:,0],X[:,1])
# plt.show()
y=iris.target
print(y)
plt.scatter(X[y==0,0],X[y==0,1],color="red",marker="o")
plt.scatter(X[y==1,0],X[y==1,1],color="blue",marker="+")
plt.scatter(X[y==2,0],X[y==2,1],color="green",marker="x")
plt.show()