screeplot(PCA,type="lines") Error in plot.new() : figure margins too large

时间: 2024-01-22 08:21:01 浏览: 33
这个错误通常是由于图形区域的边界框太大而导致的。可以通过增加边界框的大小来解决此问题。尝试使用par()函数来设置边界框的大小,例如: ``` par(mar=c(5,5,2,2)) # 设置边界框的大小 screeplot(PCA,type="lines") ``` 这将设置边界框的边距,左、右、上、下为5、5、2和2。你可以根据需要更改这些值。
相关问题

tsne <- Rtsne(as.matrix(optdigits[,1:3]), check_duplicates = FALSE, pca = FALSE, perplexity=30, theta=0.5, dims=2) Error in .check_tsne_params(nrow(X), dims = dims, perplexity = perplexity, : perplexity is too large for the number of samples

这个错误提示是因为你设置的 perplexity 参数过大,超过了样本数量的上限。t-SNE 的 perplexity 参数应该设置在 5 到 50 之间,如果 perplexity 参数设置过大,t-SNE 就无法正确地计算样本之间的距离和相似度。 你可以尝试将 perplexity 参数降低到一个合适的范围,比如设置为 10 或 20,然后再运行代码。另外,你也可以考虑使用 PCA 对数据进行降维处理,将维度减少到一个较小的范围内,然后再进行 t-SNE 的计算和可视化。

PCA=princomp(new_data,cor=T) Error in cov.wt(z) : 'x' must contain finite values only

这个错误通常表示输入数据包含缺失值或无穷大的值。你可以尝试使用 `complete.cases()` 函数来删除包含缺失值的观测值,或者使用 `is.finite()` 函数来删除包含无穷大值的观测值。例如: ``` r # 删除包含缺失值的观测值 new_data <- new_data[complete.cases(new_data),] # 删除包含无穷大值的观测值 new_data <- new_data[is.finite(new_data),] # 运行主成分分析 PCA <- princomp(new_data, cor=T) ``` 如果你仍然遇到问题,请检查你的数据是否正确,并确保所有的值都是数值型数据。

相关推荐

在下面代码中添加一个可视化图,用来画出r经过t_sne之后前15行数据的图 import pandas as pd from sklearn import cluster from sklearn import metrics import matplotlib.pyplot as plt from sklearn.manifold import TSNE from sklearn.decomposition import PCA def k_means(data_set, output_file, png_file, png_file1, t_labels, score_file, set_name): model = cluster.KMeans(n_clusters=7, max_iter=1000, init="k-means++") model.fit(data_set) # print(list(model.labels_)) p_labels = list(model.labels_) r = pd.concat([data_set, pd.Series(model.labels_, index=data_set.index)], axis=1) r.columns = list(data_set.columns) + [u'聚类类别'] print(r) # r.to_excel(output_file) with open(score_file, "a") as sf: sf.write("By k-means, the f-m_score of " + set_name + " is: " + str(metrics.fowlkes_mallows_score(t_labels, p_labels))+"\n") sf.write("By k-means, the rand_score of " + set_name + " is: " + str(metrics.adjusted_rand_score(t_labels, p_labels))+"\n") '''pca = PCA(n_components=2) pca.fit(data_set) pca_result = pca.transform(data_set) t_sne = pd.DataFrame(pca_result, index=data_set.index)''' t_sne = TSNE() t_sne.fit(data_set) t_sne = pd.DataFrame(t_sne.embedding_, index=data_set.index) plt.rcParams['font.sans-serif'] = ['SimHei'] plt.rcParams['axes.unicode_minus'] = False dd = t_sne[r[u'聚类类别'] == 0] plt.plot(dd[0], dd[1], 'r.') dd = t_sne[r[u'聚类类别'] == 1] plt.plot(dd[0], dd[1], 'go') dd = t_sne[r[u'聚类类别'] == 2] plt.plot(dd[0], dd[1], 'b*') dd = t_sne[r[u'聚类类别'] == 3] plt.plot(dd[0], dd[1], 'o') dd = t_sne[r[u'聚类类别'] == 4] plt.plot(dd[0], dd[1], 'm.') dd = t_sne[r[u'聚类类别'] == 5] plt.plot(dd[0], dd[1], 'co') dd = t_sne[r[u'聚类类别'] == 6] plt.plot(dd[0], dd[1], 'y*') plt.savefig(png_file) '''plt.scatter(data_set.iloc[:, 0], data_set.iloc[:, 1], c=model.labels_) plt.savefig(png_file) plt.clf()''' frog_data = pd.read_csv("D:/PyCharmPython/pythonProject/mfcc3.csv") tLabel = [] for family in frog_data['name']: if family == "A": tLabel.append(0) elif family == "B": tLabel.append(1) elif family == "C": tLabel.append(2) elif family == "D": tLabel.append(3) elif family == "E": tLabel.append(4) elif family == "F": tLabel.append(5) elif family == "G": tLabel.append(6) scoreFile = "D:/PyCharmPython/pythonProject/scoreOfClustering.txt" first_set = frog_data.iloc[:, 1:1327] k_means(first_set, "D:/PyCharmPython/pythonProject/kMeansSet_1.xlsx", "D:/PyCharmPython/pythonProject/kMeansSet_2.png", "D:/PyCharmPython/pythonProject/kMeansSet_2_1.png", tLabel, scoreFile, "Set_1")

import pandas as pd import numpy as np import matplotlib.pyplot as plt from sklearn import datasets from mpl_toolkits.mplot3d import Axes3D from sklearn.decomposition import PCA from sklearn.preprocessing import StandardScaler data=pd.read_csv('H:/analysis_results/mean_HN.csv') data.head() x=data.iloc[:,1:7] y=data.iloc[:,6] scaler=StandardScaler() scaler.fit(x) x_scaler=scaler.transform(x) print(x_scaler.shape) pca=PCA(n_components=3) x_pca=pca.fit_transform(x_scaler) print(x_pca.shape) #查看各个主成分对应的方差大小和占全部方差的比例 #可以看到前2个主成分已经解释了样本分布的90%的差异了 print('explained_variance_:',pca.explained_variance_) print('explained_variance_ratio_:',pca.explained_variance_ratio_) print('total explained variance ratio of first 6 principal components:',sum(pca.explained_variance_ratio_)) #将分析的结果保存成字典 result={ 'explained_variance_:',pca.explained_variance_, 'explained_variance_ratio_:',pca.explained_variance_ratio_, 'total explained variance ratio:',np.sum(pca.explained_variance_ratio_)} df=pd.DataFrame.from_dict(result,orient='index',columns=['value']) df.to_csv('H:/analysis_results/Cluster analysis/pca_explained_variance_HN.csv') #可视化各个主成分贡献的方差 #fig1=plt.figure(figsize=(10,10)) #plt.rcParams['figure.dpi'] = 300#设置像素参数值 plt.rcParams['path.simplify'] = False#禁用抗锯齿效果 plt.figure() plt.plot(np.arange(1,4),pca.explained_variance_,color='blue', linestyle='-',linewidth=2) plt.xticks(np.arange(1, 4, 1))#修改X轴间隔为1 plt.title('PCA_plot_HN') plt.xlabel('components_n',fontsize=16) plt.ylabel('explained_variance_',fontsize=16) #plt.savefig('H:/analysis_results/Cluster analysis/pca_explained_variance_HN.png') plt.show(),想要将得出的结果value为3个标签PC1,PC2,PC3,如何修改

最新推荐

recommend-type

PCA降维python的代码以及结果.doc

理解 “使用Numpy模拟PCA计算过程”与“使用sklearn进行PCA降维运算”两种方法;把 iris四维数据集降维,画出散点图
recommend-type

舵机控制中PCA9685控制芯片的运用.docx

有关舵机控制中PCA9685控制芯片的运用 文章采用I2C总线通信方式, 将PCA9685LED控制芯片应用在舵机控制中。PCA9685接收主控芯片的指令, 通过输出PWM脉冲信号的方式用以控制最多不超过16路舵机或其他输出通道, 最终...
recommend-type

具体介绍sklearn库中:主成分分析(PCA)的参数、属性、方法

文章目录主成分分析(PCA)Sklearn库中PCA一、参数说明(Parameters)二、属性(Attributes)三、方法(Methods)四、示例(Sample)五、参考资料(Reference data) 主成分分析(PCA) 主成分分析(Principal ...
recommend-type

【车牌识别】 GUI BP神经网络车牌识别(带语音播报)【含Matlab源码 668期】.zip

Matlab领域上传的视频均有对应的完整代码,皆可运行,亲测可用,适合小白; 1、代码压缩包内容 主函数:main.m; 调用函数:其他m文件;无需运行 运行结果效果图; 2、代码运行版本 Matlab 2019b;若运行有误,根据提示修改;若不会,私信博主; 3、运行操作步骤 步骤一:将所有文件放到Matlab的当前文件夹中; 步骤二:双击打开main.m文件; 步骤三:点击运行,等程序运行完得到结果; 4、仿真咨询 如需其他服务,可私信博主或扫描视频QQ名片; 4.1 博客或资源的完整代码提供 4.2 期刊或参考文献复现 4.3 Matlab程序定制 4.4 科研合作
recommend-type

【作业视频】六年级第1讲--计算专项训练(2022-10-28 22-51-53).mp4

【作业视频】六年级第1讲--计算专项训练(2022-10-28 22-51-53).mp4
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

实现实时数据湖架构:Kafka与Hive集成

![实现实时数据湖架构:Kafka与Hive集成](https://img-blog.csdnimg.cn/img_convert/10eb2e6972b3b6086286fc64c0b3ee41.jpeg) # 1. 实时数据湖架构概述** 实时数据湖是一种现代数据管理架构,它允许企业以低延迟的方式收集、存储和处理大量数据。与传统数据仓库不同,实时数据湖不依赖于预先定义的模式,而是采用灵活的架构,可以处理各种数据类型和格式。这种架构为企业提供了以下优势: - **实时洞察:**实时数据湖允许企业访问最新的数据,从而做出更明智的决策。 - **数据民主化:**实时数据湖使各种利益相关者都可
recommend-type

云原生架构与soa架构区别?

云原生架构和SOA架构是两种不同的架构模式,主要有以下区别: 1. 设计理念不同: 云原生架构的设计理念是“设计为云”,注重应用程序的可移植性、可伸缩性、弹性和高可用性等特点。而SOA架构的设计理念是“面向服务”,注重实现业务逻辑的解耦和复用,提高系统的灵活性和可维护性。 2. 技术实现不同: 云原生架构的实现技术包括Docker、Kubernetes、Service Mesh等,注重容器化、自动化、微服务等技术。而SOA架构的实现技术包括Web Services、消息队列等,注重服务化、异步通信等技术。 3. 应用场景不同: 云原生架构适用于云计算环境下的应用场景,如容器化部署、微服务
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。