简体   繁体   English

graphlab创建sframe如何获取SArray中位数

[英]graphlab create sframe how to get SArray median

I'm studying graphlab create with 我正在研究graphlab创建

data=graphlab.SFrame.read_csv('test.csv')

im trying to get median of one of columns 我试图获得列之一的中位数

data_train.fillna(('Credit_History',data_train['Credit_History'].median()))

but I got error 但我有错误

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-247-50ed3eb09dcc> in <module>()
----> 1 data_train.fillna(('Credit_History',data_train['Credit_History'].median()))

AttributeError: 'SArray' object has no attribute 'median'

data.show() will show median of this column though anyone knows how to fix this? 尽管有人知道如何解决此问题,但data.show()将显示此列的中位数?

I think I understand what your trying to do. 我想我了解您的尝试。 Sframe doesn't have a default median function. Sframe没有默认的中位数函数。 I would improvise like this: 我会像这样即兴创作:

import numpy as np
data_train.fillna('Credit_History', np.median(data_train['Credit_History']))

SArray doesn't have a median method. SArray没有中值方法。 The best way to get the median is through the sketch_summary method, then quantile . 获得中位数的最佳方法是通过sketch_summary方法,然后进行quantile More info on the sketch summary at 有关草图摘要的更多信息,请参见

https://turi.com/products/create/docs/generated/graphlab.Sketch.html https://turi.com/products/create/docs/generated/graphlab.Sketch.html

import numpy as np
import graphlab as gl

sf = gl.SFrame(np.random.rand(100))

sketch = sf['X1'].sketch_summary()
median = sketch.quantile(0.5)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM