pyspark - 错误:AttributeError:“DataFrame”对象没有属性“_jdf”
问题描述
我想使用 pyspark 执行 k 折交叉验证来微调参数,我正在使用 pyspark.ml。我收到属性错误。
AttributeError:“DataFrame”对象没有属性“_jdf”
我最初尝试使用 pyspark.mllib 但未能成功执行 k 折交叉验证
import pandas as pd
from pyspark import SparkConf, SparkContext
from pyspark.ml.classification import DecisionTreeClassifier
data=pd.read_csv("file:///SparkCourse/wdbc.csv", header=None)
type(data)
print(data)
conf = SparkConf().setMaster("local").setAppName("SparkDecisionTree")
sc = SparkContext(conf = conf)
# Create initial Decision Tree Model
dt = DecisionTreeClassifier(labelCol="label", featuresCol="features",
maxDepth=3)
# Train model with Training Data
dtModel = dt.fit(data)
# I expect the model to be trained but I'm getting the following error
AttributeError: 'DataFrame' object has no attribute '_jdf'
注意:我可以打印数据。错误在 dtModel
解决方案
将 Panadas 转换为 Spark
from pyspark.sql import SQLContext
sc = SparkContext.getOrCreate()
sqlContext = SQLContext(sc)
spark_dff = sqlContext.createDataFrame(panada_df)
推荐阅读
- python - 如何使用 python attrs 为可变属性提供默认值?
- amazon-web-services - 查看 AWS 对资源使用的权限?
- node.js - 无法从命令行运行 clasp
- sql-server - 如何在 VARCHAR(MAX) 中的 SQL Server 中的两个已知字符串之间选择可变长度字符串,其中某些列没有适用的字符串
- javascript - RegExp for Postal Code, faster/better way?
- ios - Swift:复制/粘贴特定字段的启用和禁用
- java - 让 maven surefire 在存在 module-info.java 文件的类路径上运行
- d3.js - D3 - 将 y 轴标签移到线上
- java - Java中的空检查是否需要大量时间?
- reactjs - React BarChart 使用 D3 可滚动 X 轴