# 可视化前两个主成分plt.figure(figsize=(10, 6))sns.scatterplot(x=pca_features[:, 0], y=pca_features[:, 1], hue=df['spending_score'], palette='viridis')plt.title('PCA - 可视化前两个主成分')plt.xlabel('主成分-1')plt.ylabel('主成分-2')plt.colorbar(label='Spending Score')plt....
plt.title('Scatter Plot') plt.xlabel('X-axis') plt.ylabel('Y-axis') plt.tight_layout() plt.show() 在PCA.xlsx同一目录下保存为main.py 然后安装好需要的库。 便可在命令行下运行 pythonmain.py 3.结果
AI代码解释 # Plot plt.scatter(X_train_pd[0],X_train_pd[1],c=y_train,alpha=0.8)plt.title('Scatter plot')plt.xlabel('x0')plt.ylabel('x1')plt.show() 下面的代码用于构建模型,并对训练数据和测试数据进行评分。 label_:训练数据的标签向量,当使用.predict()训练数据时也一样。 decision_scores...
transform(X) # Plot scores plt.scatter(scores[:,0], scores[:,1]) plt.xlabel('PC1') plt.ylabel('PC2') plt.title('PCA of Auto Data') plt.show() 第二步,因子分析 import pandas as pd import numpy as np from factor_analyzer import FactorAnalyzer # perform factor analysis n_factors =...
plt.ylabel('Second Principal Component')#设置标题plt.title("PCA Scatter Plot")#显示图形plt.show() 显示:
可以使用subplot()快速绘制包含多个子图的图表,它的调用形式如下: subplot(numRows, numCols, plotNum) subplot将整个绘图区域等分为numRows行* numCols列个子区域,然后按照从左到右,从上到下的顺序对每个子区域进行编号,左上的子区域的编号为1。如果numRows,numCols和plotNum这三个数都小于10的话,可以把它们...
plt.scatter(x, y, c=colors[i])#设置图例,0-9用不同颜色表示plt.legend(digits.target_names, bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)#设置坐标标签plt.xlabel('First Principal Component') plt.ylabel('Second Principal Component')#设置标题plt.title("PCA Scatter Plot")#显示图形pl...
sns.scatterplot(x="comp-1", y="comp-2") 该图显示了MNIST数据的变化维度。颜色定义了目标数字和它们的特征数据在图中的位置。 在本教程中,我们已经简单了解了如何用稀疏和高斯随机投影方法以及Python中的PCA方法来减少数据维度。 最受欢迎的见解
class_distr = []# Plot the different class distributionsfor i, l in enumerate(np.unique(y)):_x1 = x1[y == l]_x2 = x2[y == l]_y = y[y == l]class_distr.append(plt.scatter(_x1, _x2, color=colors[i])) # Add a legendplt.l...