简体   繁体   中英

graphlab create sframe how to get SArray median

I'm studying graphlab create with

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?

I think I understand what your trying to do. Sframe doesn't have a default median function. 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. The best way to get the median is through the sketch_summary method, then quantile . More info on the sketch summary at

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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