Pyspark回归--AFTSurvivalRegression

AFTSurvivalRegression

class pyspark.ml.regression.AFTSurvivalRegression(featuresCol=‘features’, labelCol=‘label’, predictionCol=‘prediction’, fitIntercept=True, maxIter=100, tol=1e-06, censorCol=‘censor’, quantileProbabilities=[0.01, 0.05, 0.1, 0.25, 0.5, 0.75, 0.9, 0.95, 0.99], quantilesCol=None, aggregationDepth=2)

加速失效时间 (AFT) 模型生存回归 根据生存时间的 Weibull 分布拟合参数 AFT 生存回归模型。

aggregationDepth = Param(parent=‘undefined’, name=‘aggregationDepth’, doc=‘树聚合 (>= 2) 的建议深度。’

censorCol = Param(parent=‘undefined’, name=‘censorCol’, doc=‘censor 列名。该列的值可以是0或1。如果值为1,则表示事件已经发生,即未经审查;否则审查。’)

fitIntercept = Param(parent=‘undefined’, name=‘fitIntercept’, doc=‘是否适合截取项。’)

quantileProbabilities = Param(parent=‘undefined’, name=‘quantileProbabilities’, doc=‘quantile probabilities array。分位数概率数组的值应该在 (0, 1) 范围内,并且数组应该是非空的。’)

quantilesCol = Param(parent=‘undefined’, name=‘quantilesCol’, doc=‘quantiles 列名。如果设置了,该列将输出对应的 quantileProbabilities 的分位数。’)

tol = Param(parent=‘undefined’, name=‘tol’, doc=‘迭代算法的收敛容差 (>= 0).’)

model.coefficients:模型系数

model.predictQuantiles(features):预测分位数

model.scale:模型比例参数

01.创建数据集

from pyspark.sql import SparkSession
spark = SparkSession.builder.config("spark.driver.host","192.168.1.10")\
    .config("spark.ui.showConsoleProgress","false")\
    .appName("AFTSurvivalRegression").master("local[*]").getOrCreate()
from pyspark.ml.linalg import Vectors
df = spark.createDataFrame([
    (1.0, Vectors.dense(1.0), 1.0),
    (1e-40, Vectors.sparse(1, [], []), 0.0)], ["label", "features", "censor"])
df.show()
df.printSchema()

​ 输出结果:

+-------+---------+------+
|  label| features|censor|
+-------+---------+------+
|    1.0|    [1.0]|   1.0|
|1.0E-40|(1,[],[])|   0.0|
+-------+---------+------+

root
 |-- label: double (nullable = true)
 |-- features: vector (nullable = true)
 |-- censor: double (nullable = true)

02.构建模型转换原始数据并进行查看

from pyspark.ml.regression import AFTSurvivalRegression
aftsr = AFTSurvivalRegression()
model = aftsr.fit(df)
model.transform(df).show()

​ 输出结果:

+-------+---------+------+----------+
|  label| features|censor|prediction|
+-------+---------+------+----------+
|    1.0|    [1.0]|   1.0|       1.0|
|1.0E-40|(1,[],[])|   0.0|       1.0|
+-------+---------+------+----------+

03.使用模型对数据进行预测

print(model.predict(Vectors.dense(6.3)))

​ 输出结果:

1.0

04.查看预测分位数

print(model.predictQuantiles(Vectors.dense(6.3)))

​ 输出结果:

[0.010050335853501452,
0.05129329438755058,
0.1053605156578263,
0.2876820724517809,
0.6931471805599453,
1.3862943611198906,
2.302585092994046,
2.99573227355399,
4.605170185988092]
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值