如何使用Python提取点的x坐标

我正在尝试构建一个用于主题提取的NMF模型。为了重新训练模型,我需要向nmf函数传递一个参数,而这个参数需要从算法返回的给定点中提取x坐标。以下是参考代码:

no_features = 1000no_topics = 9print ('Old number of topics: ', no_topics)tfidf_vectorizer = TfidfVectorizer(max_df = 0.95, min_df = 2, max_features = no_features, stop_words = 'english')tfidf = tfidf_vectorizer.fit_transform(documents)tfidf_feature_names = tfidf_vectorizer.get_feature_names()no_topics = tfidf.shapeprint('New number of topics :', no_topics)# nmf = NMF(n_components = no_topics, random_state = 1, alpha = .1, l1_ratio = .5, init = 'nndsvd').fit(tfidf)

倒数第三行中,tfidf.shape返回一个点(3,1000)给变量’no_topics’,然而我希望这个变量只设置为x坐标,即(3)。我如何只提取这个点的x坐标呢?


回答:

你可以使用no_topics[0]来选择第一个值

print('New number of topics : {}'.format(no_topics[0]))

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注