1.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import warnings
warnings.filterwarnings(action = 'ignore')
%matplotlib inline
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus']=False
from sklearn.datasets import make_blobs
from sklearn.feature_selection import f_classif
from sklearn import decomposition
from sklearn.cluster import KMeans,AgglomerativeClustering
from sklearn.metrics import silhouette_score,calinski_harabasz_score
import scipy.cluster.hierarchy as sch
from itertools import cycle
from matplotlib.patches import Ellipse
from sklearn.mixture import GaussianMixture
N=100
X1, y1 = make_blobs(n_samples=N, centers=4, n_features=2,random_state=0) #2 特征
X2, y2 = make_blobs(n_samples=N, centers=4, n_features=3,random_state=123) #3 特征
print('y1=',y1)
print('y2=',y2)
y1= [0 3 0 0 0 0 2 3 0 3 3 3 3 3 3 1 1 2 2 1 0 3 2 1 0 2 2 0 1 1 1 3 1
1 2 0 3
1 3 2 0 2 3 2 2 3 1 2 0 0 0 1 2 2 2 3 3 1 1 3 3 1 1 0 1 3 2 2 1 0 3 1
0 3
0 0 2 2 1 1 1 3 2 0 1 2 1 1 0 0 0 2 0 2 2 3 3 2 3 0]
y2= [2 0 1 3 2 2 1 0 2 1 0 1 1 0 1 3 0 0 3 1 0 3 1 0 3 1 1 0 2 2 0 3 3
3 3 2 0
0 3 1 2 0 3 0 2 2 2 2 0 2 1 0 1 3 0 1 2 3 0 1 1 2 2 3 2 3 3 3 1 1 0 3
2 2
0 1 2 3 2 3 1 1 0 2 0 2 3 3 0 1 1 1 3 3 2 0 1 2 3 0]
2.
plt.figure(figsize=(18,12))
plt.subplot(121)
plt.scatter(X1[:,0],X1[:,1],s=50)
plt.xlabel("X1-1")
plt.ylabel("X1-2")
plt.title("%d 个样本观测点的分布"%N)
ax=plt.subplot(122, projection='3d')
ax.scatter(X2[:,0],X2[:,1],X2[:,2],c='blue')
ax.set_xlabel("X2-1")