关于pip line的介绍

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Jun  7 16:49:03 2018@author: luogan
"""from pyspark.ml import Pipeline
from pyspark.ml.classification import LogisticRegression
from pyspark.ml.feature import HashingTF, Tokenizerfrom pyspark.sql import SparkSessionspark= SparkSession\.builder \.appName("dataFrame") \.getOrCreate()# Prepare training documents from a list of (id, text, label) tuples.
training = spark.createDataFrame([(0, "a b c d e spark", 1.0),(1, "b d", 0.0),(2, "spark f g h", 1.0),(3, "hadoop mapreduce", 0.0)
], ["id", "text", "label"])# Configure an ML pipeline, which consists of three stages: tokenizer, hashingTF, and lr.
tokenizer = Tokenizer(inputCol="text", outputCol="words")
hashingTF = HashingTF(inputCol=tokenizer.getOutputCol(), outputCol="features")
lr = LogisticRegression(maxIter=10, regParam=0.001)
pipeline = Pipeline(stages=[tokenizer, hashingTF, lr])# Fit the pipeline to training documents.
model = pipeline.fit(training)# Prepare test documents, which are unlabeled (id, text) tuples.
test = spark.createDataFrame([(4, "spark i j k"),(5, "l m n"),(6, "spark hadoop spark"),(7, "apache hadoop")
], ["id", "text"])# Make predictions on test documents and print columns of interest.
prediction = model.transform(test)
selected = prediction.select("id", "text", "probability", "prediction")
for row in selected.collect():rid, text, prob, prediction = rowprint("(%d, %s) --> prob=%s, prediction=%f" % (rid, text, str(prob), prediction))
(4, spark i j k) --> prob=[0.15554371384424398,0.844456286155756], prediction=1.000000
(5, l m n) --> prob=[0.8307077352111738,0.16929226478882617], prediction=0.000000
(6, spark hadoop spark) --> prob=[0.06962184061952888,0.9303781593804711], prediction=1.000000
(7, apache hadoop) --> prob=[0.9815183503510166,0.018481649648983405], prediction=0.000000

pyspark pipline相关推荐

  1. pyspark入门---机器学习实战预测婴儿出生率(二)使用ML库

    机器学习实战预测婴儿出生率 1.加载数据 2.创建转换器 3.创建预测器 4.创建管道 5.训练模型 6.使用BinaryClassificationEvaluator对模型评估 7.模型保存与调用 ...

  2. pyspark汇总小结

    20220402 Spark报Total size of serialized results of 12189 tasks is bigger than spark.driver.maxResult ...

  3. spark- PySparkSQL之PySpark解析Json集合数据

    PySparkSQL之PySpark解析Json集合数据 数据样本 12341234123412342|asefr-3423|[{"name":"spark", ...

  4. jupyter笔记本_如何为Jupyter笔记本电脑设置PySpark

    jupyter笔记本 by Tirthajyoti Sarkar 由Tirthajyoti Sarkar 如何为Jupyter笔记本电脑设置PySpark (How to set up PySpark ...

  5. 手把手教你实现PySpark机器学习项目——回归算法

    作者 | hecongqing 来源 | AI算法之心(ID:AIHeartForYou) [导读]PySpark作为工业界常用于处理大数据以及分布式计算的工具,特别是在算法建模时起到了非常大的作用. ...

  6. pyspark常用API

    union 和unionall union 纵向合并dataframe In this Spark article, you will learn how to union two or more d ...

  7. 利用PySpark进行迁移学习的多类图像分类

    在本文中,我们将演示计算机视觉问题,它具有结合两种最先进技术的能力:深度学习和Apache Spark.我们将利用深度学习管道的强大功能来解决多类图像分类问题. PySpark 是 Spark 为 P ...

  8. pyspark dataframe数据连接(join)、转化为pandas dataframe、基于多个字段删除冗余数据

    pyspark dataframe数据连接(join).转化为pandas dataframe.基于多个字段删除冗余数据 目录 pyspark dataframe数据连接(join).转化为panda ...

  9. 基于关联规则(Variational Autoencoders)疾病预测系统实战:(pyspark FPGrowth实现频繁项集挖掘、最后给出预测模型topK准确率和召回率)

    基于关联规则(Variational Autoencoders)疾病预测系统实战:(pyspark FPGrowth实现频繁项集挖掘.最后给出预测模型topK准确率和召回率) 目录

最新文章

  1. 苹果首席设计官离职!这个被称为“强纳肾”的男人,设计了iMac、iPhone等无数产品...
  2. yabailv 运放_运放入门
  3. c语言 错误 无效的控制谓词,PAT 1025反转链表的代码实现及错误分析(C语言)
  4. http/https监控获取响应时间(DNS解析时间,RRT时间,服务器处理时间等)
  5. 第十三节:实际开发中使用最多的监视锁Monitor、lock语法糖的扩展、混合锁的使用(ManualResetEvent、SemaphoreSlim、ReaderWriterLockSlim)
  6. 【PostgreSQL】PostgreSQL安装步骤
  7. 仅需6道题轻松掌握SciPy空间计算基础 | Python技能树征题
  8. Android设计模式--之命令模式
  9. RS485使用串口输出最后一个字节固定为FF
  10. 计算机上安装了新的ie版本,win7电脑自带的IE11浏览器如何降级到IE8
  11. 如何做项目总结与汇报
  12. VBA学习笔记五---如何将宏代码进行共享(加载宏)
  13. 如何创建SQL Server Management Studio 18(SSMS)扩展
  14. 200元组群晖—HP惠普T610瘦客户端:直接硬盘启动黑群晖
  15. linux系统安装firefox的flash player插件
  16. 计算机组装在线作业_1,中石油华东《计算机维护技术》2018年秋学期在线作业(三).doc...
  17. PredRNN++:网络结构和代码解读
  18. 小米智能插排内部结构
  19. 手机怎么模拟弱网_手游测试之模拟弱网环境测试
  20. Python中使用MySQL

热门文章

  1. 在矩阵中查找字符串 Word Search
  2. 查看安装的react-native和react版本
  3. rac_安装软件时报版本号过高问题
  4. openStack镜像制作
  5. 25个经典的Spring面试问答
  6. bash history 命令记录日志 实时发送到syslog server
  7. 如何从eclipse迁移到idea
  8. Excel函数应用教程:数据库函数
  9. 几个关于财报的基本知识
  10. Android11还能自定义相机吗,安卓用户又少了一项自由,Android 11不再支持更改默认相机程序...