python机器学习-乳腺癌细胞挖掘(博主亲自录制视频)
https://study.163.com/course/introduction.htm?courseId=1005269003&utm_campaign=commission&utm_source=cp-400000000398149&utm_medium=share
生成2类数据
n_features :特征个数= n_informative() + n_redundant + n_repeated
n_informative:多信息特征的个数
n_redundant:冗余信息,informative特征的随机线性组合
n_repeated :重复信息,随机提取n_informative和n_redundant 特征
n_classes:分类类别
n_clusters_per_class :某一个类别是由几个cluster构成的
from sklearn import preprocessing import numpy as np #生成分类数据的分类器 from sklearn.datasets.samples_generator import make_classification #自动生成训练数据和测试数据 from sklearn.cross_validation import train_test_split #导入支持向量模型 from sklearn.svm import SVC import matplotlib.pyplot as plt x,y=make_classification(n_samples=300,n_features=2,n_redundant=0,n_informative=2,random_state=22,n_clusters_per_class=1,scale=100) #c=y表示color为黄色 plt.scatter(x[:,0],x[:,1],c=y) plt.show()
生成4类数据
# -*- coding: utf-8 -*- """ Created on Sun Jan 7 15:54:56 2018 @author: Administrator """ from sklearn import preprocessing import numpy as np #生成分类数据的分类器 from sklearn.datasets.samples_generator import make_classification #自动生成训练数据和测试数据 from sklearn.cross_validation import train_test_split #导入支持向量模型 from sklearn.svm import SVC import matplotlib.pyplot as plt #n_classes=4生成4类数据 x,y=make_classification(n_classes=4,n_samples=300,n_features=2,n_redundant=0,n_informative=2,random_state=22,n_clusters_per_class=1,scale=100) #c=y表示color为黄色 plt.scatter(x[:,0],x[:,1],c=y) plt.show()
# -*- coding: utf-8 -*- """ Created on Sun Jan 7 16:51:38 2018 @author: Administrator """ import matplotlib.pyplot as plt from sklearn.datasets import make_classification from sklearn.datasets import make_blobs from sklearn.datasets import make_gaussian_quantiles from sklearn.datasets import make_hastie_10_2 plt.figure(figsize=(8, 8)) plt.subplots_adjust(bottom=.05, top=.9, left=.05, right=.95) plt.subplot(421) plt.title("One informative feature, one cluster per class", fontsize='small') X1, Y1 = make_classification(n_samples=1000,n_features=2, n_redundant=0, n_informative=1, n_clusters_per_class=1) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.subplot(422) plt.title("Two informative features, one cluster per class", fontsize='small') X1, Y1 = make_classification(n_samples=1000,n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.subplot(423) plt.title("Two informative features, two clusters per class", fontsize='small') X2, Y2 = make_classification(n_samples=1000,n_features=2, n_redundant=0, n_informative=2) plt.scatter(X2[:, 0], X2[:, 1], marker='o', c=Y2) plt.subplot(424) plt.title("Multi-class, two informative features, one cluster", fontsize='small') X1, Y1 = make_classification(n_samples=1000,n_features=2, n_redundant=0, n_informative=2, n_clusters_per_class=1, n_classes=3) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.subplot(425) plt.title("Three blobs", fontsize='small') X1, Y1 = make_blobs(n_samples=1000,n_features=2, centers=3) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.subplot(426) plt.title("Gaussian divided into four quantiles", fontsize='small') X1, Y1 = make_gaussian_quantiles(n_samples=1000,n_features=2, n_classes=4) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.subplot(427) plt.title("hastie data ", fontsize='small') X1, Y1 = make_hastie_10_2(n_samples=1000) plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1) plt.show()
# -*- coding: utf-8 -*- """ Created on Sun Jan 7 16:29:35 2018 @author: Administrator """ import matplotlib.pyplot as plt from sklearn.datasets import make_classification from sklearn.datasets import make_blobs from sklearn.datasets import make_gaussian_quantiles from sklearn.datasets import make_hastie_10_2 #画布的大小为长20cm高20cm plt.figure(figsize=(15,10)) #标题,fontsize为标题字体大小 plt.title("Gaussian divided into six quantiles", fontsize='large') X1, Y1 = make_gaussian_quantiles(n_samples=1000,n_features=2, n_classes=6) #绘制点,X1[:, 0]为点的x列表值, X1[:, 1]为点的y列表值, c=Y1表示颜色,c为color缩写 plt.scatter(X1[:, 0], X1[:, 1], marker='o', c=Y1)
# -*- coding: utf-8 -*- """ Created on Sun Jan 7 16:51:38 2018 @author: Administrator """ from sklearn.datasets import make_circles from sklearn.datasets import make_moons import matplotlib.pyplot as plt import numpy as np #画布的大小为长20cm高20cm plt.figure(figsize=(15,10)) fig=plt.figure(1) x1,y1=make_circles(n_samples=1000,factor=0.5,noise=0.1) plt.subplot(121) plt.title('make_circles function example') plt.scatter(x1[:,0],x1[:,1],marker='o',c=y1) plt.subplot(122) x1,y1=make_moons(n_samples=1000,noise=0.1) plt.title('make_moons function example') plt.scatter(x1[:,0],x1[:,1],marker='o',c=y1) plt.show()
https://study.163.com/provider/400000000398149/index.htm?share=2&shareId=400000000398149( 欢迎关注博主主页,学习python视频资源,还有大量免费python经典文章)