分类-iris dataset

构造特征组合

import pandas as pd 
import numpy as np 
import matplotlib.pyplot as plt
from sklearn.cluster import KMeans
from sklearn import datasets  

def main():
	'''	
	iris = pd.read_csv('F:\\AI_code\\Iris\\Iris.csv')

	#print(iris.data[:,2:4])
	x1 = iris['SepalLength']
	y1 = iris['SepalWidth']

	x2 = iris['PetalLength']
	y2 = iris['PetalWidth']

	plt.figure()
	plt.scatter(x1,y1,s=30,c='r')
	#plt.scatter(x2,y2,s=30,c='y')
	plt.xlabel('x-lable')
	plt.ylabel('y-label')
	plt.legend()
	plt.title('Scatter')
	plt.show()
'''
	iris = datasets.load_iris()
	X1 = iris.data[:, :2] ##表示我们只取特征空间中的后两个维度
	X2 = iris.data[:,2:4]
	X3 = iris.data[:,[0,2]]
	print(X3)
	print(X2.shape)
	txt = [i for i in range(1,151)]
	print(txt[:])

	plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
	#绘制数据分布图
	plt.scatter(X1[:, 0]*X1[:, 1]+1, X1[:, 1], c = "r", marker='o', label='class-1')  
	#plt.scatter(X1[:, 0]*X1[:, 1], X1[:, 1], c = "r", marker='o', label='class-1')  
	plt.scatter(X2[:, 0], X2[:, 1]-2, c = "g", marker='o', label='class-2')
	plt.scatter(X3[:, 0], X3[:, 1], c = "b", marker='o', label='class-3')

	x=X1[:, 0]
	y=X1[:, 1]
	#plt.scatter(x, y)
	#for i in range(len(X1[:,0])):
	#	if i >100:
	#		plt.annotate(txt[i],xy = (x[i], y[i]), xytext = (x[i]+0.01, y[i]+0.01))

	plt.xlabel('x')  
	plt.ylabel('y')  
	plt.legend()  
	plt.show()  

if __name__ == '__main__':
	main()

另外参考:

https://blog.csdn.net/orangefly0214/article/details/78668136

你可能感兴趣的:(机器学习)