频道栏目
首页 > 资讯 > 云计算 > 正文

spark自带的logistic_regression例子分析

18-06-06        来源:[db:作者]  
收藏   我要投稿
import sys
import numpy as np
from pyspark.sql import SparkSession
D = 10  # Number of dimensions
# Read a batch of points from the input file into a NumPy matrix object. We operate on batches to
# make further computations faster.
# The data file contains lines of the form 

1. 其中map()与mapPartitions()函数区别:

map()函数是作用到数据集的每一个元素,所以它的目标是单个的元素

mapPartitions()函数作用到数据集的每个分区上,所以它的目标是迭代器(包含多个元素)

2. enumerate()函数

返回枚举对象

以下展示了使用 enumerate() 方法的实例:

>>>seasons = ['Spring', 'Summer', 'Fall', 'Winter']>>> list(enumerate(seasons))[(0, 'Spring'), (1, 'Summer'), (2, 'Fall'), (3, 'Winter')]>>> list(enumerate(seasons, start=1)) # 小标从 1 开始[(1, 'Spring'), (2, 'Summer'), (3, 'Fall'), (4, 'Winter')]

ps:readPointBatch()函数写的挺优雅的

3. numpy fromstring()将字符串转换成一维数组

Examples

>>> np.fromstring('1 2', dtype=int, sep=' ')
array([1, 2])
>>> np.fromstring('1, 2', dtype=int, sep=',')
array([1, 2])
相关TAG标签
上一篇:Android应用开发之关于this.context=context代码的解析
下一篇:YARN-client提交任务处理过程
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站