我正在尝试提取random forest classifier我使用Pyspark. 我参考了下面的文章来获得我训练的随机森林模型的特征重要性分数。
但是,当我使用本文中描述的方法时,出现以下错误
'CrossValidatorModel' object has no attribute 'featureImportances'
Run Code Online (Sandbox Code Playgroud)
这是我用来训练模型的代码
cols = new_data.columns
stages = []
label_stringIdx = StringIndexer(inputCol = 'Bought_Fibre', outputCol = 'label')
stages += [label_stringIdx]
numericCols = new_data.schema.names[1:-1]
assembler = VectorAssembler(inputCols=numericCols, outputCol="features")
stages += [assembler]
pipeline = Pipeline(stages = stages)
pipelineModel = pipeline.fit(new_data)
new_data.fillna(0, subset=cols)
new_data = pipelineModel.transform(new_data)
new_data.fillna(0, subset=cols)
new_data.printSchema()
train_initial, test = new_data.randomSplit([0.7, 0.3], seed = 1045)
train_initial.groupby('label').count().toPandas()
test.groupby('label').count().toPandas()
train_sampled = train_initial.sampleBy("label", fractions={0: 0.1, 1: 1.0}, seed=0) …Run Code Online (Sandbox Code Playgroud) machine-learning random-forest apache-spark pyspark apache-spark-mllib
我有一个字符列的数据框,我想在其中每2个字符后插入一个定界符。字符列的长度是可变的。看起来像这样
id character
1 aaabdg
2 bjdbjhdj
3 bjbkjekkechj
4 jkfb
Run Code Online (Sandbox Code Playgroud)
我想要的输出数据帧如下
id character
1 aa_ab_dg
2 bj_db_jh_dj
3 bj_bk_je_kk_ec_hj
4 jk_fb
Run Code Online (Sandbox Code Playgroud)
我一直在尝试创建正则表达式以在下面的代码中使用,但是还没有发现任何运气。
cat(paste0('[a-z]{2}', paste(str1, collapse="", ""), '[a-z]{2}'))
Run Code Online (Sandbox Code Playgroud)
和
gsub("([a-z])", "\\,", str1)
Run Code Online (Sandbox Code Playgroud)
任何帮助/建议将不胜感激
我正在研究一种机器学习形状模型1,456,354 X 53.我想为我的数据集做功能选择.我知道如何python使用以下代码进行功能选择.
from sklearn.feature_selection import RFECV,RFE
logreg = LogisticRegression()
rfe = RFE(logreg, step=1, n_features_to_select=28)
rfe = rfe.fit(df.values,arrythmia.values)
features_bool = np.array(rfe.support_)
features = np.array(df.columns)
result = features[features_bool]
print(result)
Run Code Online (Sandbox Code Playgroud)
但是,我找不到任何可以显示如何执行递归特征选择的文章pyspark.
我试图sklearn在pyspark中导入库,但是它找不到错误的sklearn模块.我正在google dataproc集群上运行pyspark.
可以请有人帮助我在pyspark实现这个目标
python machine-learning feature-selection pyspark google-cloud-dataproc