背景
1 学习python 机器学习中聚类方法,设计带有标签数据的自带工具。
2 scikit - learn 中的自带数据生成器以及函数。
3 代码如下:
`import numpy as np
from sklearn.datasets import make_classification
from matplotlib import pyplot
import pandas as pd
import warnings
warnings.filterwarnings(“ignore”)
pyplot.rcParams[“font.sans-serif”] = [“SimHei”] # 用来正常显示中文标签
pyplot.rcParams[“axes.unicode_minus”] = False # 用来正常显示负号
X, y = make_classification(n_samples=1000,
n_features=2,
n_informative=2,
n_redundant=0,
n_clusters_per_class=1,
random_state=4)
X = pd.DataFrame(X)
y = pd.DataFrame(y)
X[‘2’] = y
fig = pyplot.figure(dpi=150)
class_values = set(X[‘2’])
C_1 = X[X[‘2’].isin([0])]
C_2 = X[X[‘2’].isin([1])]
pyplot.plot(C_1[0],C_1[1], ‘C4.’, label=‘类别1’)
pyplot.plot(C_2[0],C_2[1], ‘C5x’, label=‘类别2’)
pyplot.title(‘Demo for classification’)
pyplot.xlabel(‘一坐标’)
pyplot.ylabel(‘二坐标’)
pyplot.legend()`