import numpy as np
from matplotlib import colors
from sklearn import svm
from sklearn.svm import SVC
from sklearn import model_selection
import matplotlib.pyplot as plt
import matplotlib as mpl
#对数据进行处理
data_path='D:\python learning material\iris.data'
selection=[0,2]defiris_type(s):
it ={b'Iris-setosa':0, b'Iris-versicolor':1, b'Iris-virginica':2}return it[s]defdatadivision(data_path,selection):#数据与结果分开,分隔符为“,”,第5列进行转化
data = np.loadtxt(data_path,dtype=float,delimiter=',',converters={4:iris_type})#data为二维数组,data.shape=(150, 5)
x, y = np.split(data,(4,),axis=1)#要切分的数组 #沿轴切分的位置,位置为4,5列中间 #axis参数代表纵向分割,按列分割
x = x[:, selection]#取特征值 #print(x)#print(x.shape)
x_train,x_test,y_train,y_test=model_selection.train_test_split(x,y,random_state=1,test_size=0.3)#所要划分的样本特征集#所要划分的样本结果#随机数种子#测试样本占比return x,x_train,x_test,y_train,y_test,y