草庐IT

$sklearn

全部标签

python - 在 sklearn 的双标图中绘制 PCA 加载和加载(类似于 R 的自动绘图)

我在Rw/autoplot中看到了这个教程。他们绘制了载荷和载荷标签:autoplot(prcomp(df),data=iris,colour='Species',loadings=TRUE,loadings.colour='blue',loadings.label=TRUE,loadings.label.size=3)https://cran.r-project.org/web/packages/ggfortify/vignettes/plot_pca.html我更喜欢使用Python3w/matplotlib、scikit-learn和pandas进行数据分析。但是,我不知道如何添

python - 如何仅标准化 sklearn 管道中的数字变量?

我正在尝试通过2个步骤创建一个sklearn管道:标准化数据使用KNN拟合数据但是,我的数据同时包含数字变量和分类变量,我已使用pd.get_dummies将其转换为虚拟变量。我想标准化数字变量,但让虚拟变量保持原样。我一直这样做:X=dataframecontainingbothnumericandcategoricalcolumnsnumeric=[listofnumericcolumnnames]categorical=[listofcategoricalcolumnnames]scaler=StandardScaler()X_numeric_std=pd.DataFrame(d

python - 在 sklearn 的 TfidfVectorizer 中将单词添加到 stop_words 列表

我想在TfidfVectorizer中的stop_words中再添加几个词。我遵循了Addingwordstoscikit-learn'sCountVectorizer'sstoplist中的解决方案.我的停用词列表现在包含“英语”停用词和我指定的停用词。但TfidfVectorizer仍然不接受我的停用词列表,我仍然可以在我的功能列表中看到这些词。下面是我的代码fromsklearn.feature_extractionimporttextmy_stop_words=text.ENGLISH_STOP_WORDS.union(my_words)vectorizer=TfidfVect

python - 原始 xgboost(学习 API)和 sklearn XGBClassifier(Scikit-Learn API)之间的区别

我使用下面的xgbootssklearn界面来创建和训练xgbmodel-1。clf=xgb.XGBClassifier(n_estimators=100,objective='binary:logistic',)clf.fit(x_train,y_train,early_stopping_rounds=10,eval_metric="auc",eval_set=[(x_valid,y_valid)])而xgboost模型可以通过原始xgboost创建如下model-2:param={}param['objective']='binary:logistic'param['eval_me

python - 如何通过索引自定义 sklearn 交叉验证迭代器?

类似于Customcrossvalidationsplitsklearn我想为GridSearchCV定义我自己的拆分,我需要为其自定义内置的交叉验证迭代器。我想将我自己的一组用于交叉验证的训练测试索引传递给GridSearch,而不是让迭代器为我确定它们。我在sklearn文档页面上浏览了可用的cv迭代器,但找不到它。例如我想实现这样的东西数据有9个样本对于2折cv,我创建了自己的一组训练测试指标>>>train_indices=[[1,3,5,7,9],[2,4,6,8]]>>>test_indices=[[2,4,6,8],[1,3,5,7,9]]1stfold^2ndfold^

python - sklearn : User defined cross validation for time series data

我正在尝试解决机器学习问题。我有一个包含时间序列元素的特定数据集。对于这个问题,我使用了著名的python库-sklearn。这个库中有很多交叉验证迭代器。还有几个迭代器用于自己定义交叉验证。问题是我真的不知道如何为时间序列定义简单的交叉验证。这是我想要获得的一个很好的例子:假设我们有几个时期(年),我们想将我们的数据集分成几个block,如下所示:data=[1,2,3,4,5,6,7]train:[1]test:[2](ortest:[2,3,4,5,6,7])train:[1,2]test:[3](ortest:[3,4,5,6,7])train:[1,2,3]test:[4](

python - 导入错误 : No module named sklearn (Python)

我想使用scikit-learn。我输入了pipinstall-Uscikit-learnpip3installsklearn安装它;但是当我输入$Python>>>importsklearn返回ImportError:Nomodulenamedsklearn我遵循了其他教程,但它不起作用。此外,我的环境返回此警告:Ifyouhaveinstalledscikit-learnfromsource,pleasedonotforgettobuildthepackagebeforeusingit:runpythonsetup.pyinstallormakeinthesourcedirecto

python - 添加新文本到 Sklearn TFIDIF Vectorizer (Python)

是否有添加到现有语料库的功能?我已经生成了我的矩阵,我希望定期添加到表中而无需重新处理整个sha-bang例如;articleList=['hereissometextblahblah','anothertextobject','morefooforyourbarrightnow']tfidf_vectorizer=TfidfVectorizer(max_df=.8,max_features=2000,min_df=.05,preprocessor=prep_text,use_idf=True,tokenizer=tokenize_text)tfidf_matrix=tfidf_vec

python - 在 sklearn.cross_validation 中使用 train_test_split 和 cross_val_score 的区别

我有一个包含20列的矩阵。最后一列是0/1标签。数据链接是here.我正在尝试使用交叉验证在数据集上运行随机森林。我使用两种方法来做到这一点:使用sklearn.cross_validation.cross_val_score使用sklearn.cross_validation.train_test_split当我做我认为几乎完全相同的事情时,我得到了不同的结果。为了举例说明,我使用上述两种方法运行双重交叉验证,如下面的代码所示。importcsvimportnumpyasnpimportpandasaspdfromsklearnimportensemblefromsklearn.me

python - 如何在sklearn中打印聚类结果

我有一个稀疏矩阵fromscipy.sparseimport*M=csr_matrix((data_np,(rows_np,columns_np)));然后我就这样进行聚类fromsklearn.clusterimportKMeanskm=KMeans(n_clusters=n,init='random',max_iter=100,n_init=1,verbose=1)km.fit(M)我的问题非常菜鸟:如何在没有任何额外信息的情况下打印聚类结果。我不关心绘图或距离。我只需要那样的簇行Cluster1row1row2row3Cluster2row4row20row1000...我怎样才