Group in SFrame without graphlab installed

How to use batch operation in SFrame without installing graphlab.

I would like to do some aggregation, but in all the examples on the Internet I have seen that the aggregation function comes from Graphlab.

how

import graphlab.aggregate as agg

user_rating_stats = sf.groupby(key_columns='user_id',
                          operations={
                                'mean_rating': agg.MEAN('rating'),
                                'std_rating': agg.STD('rating')
                            })

How can I use, say numpy.mean, and not agg.MEANin the above example?

+4
source share
1 answer

The package sframecontains the same aggregation module as the package graphlab, so you do not need to resort to numpy.

import sframe
import sframe.aggregate as agg

sf = sframe.SFrame({'user_id': [1, 1, 2],
                    'rating': [3.3, 3.6, 4.1]})
grp = sf.groupby('user_id', {'mean_rating': agg.MEAN('rating'),
                             'std_rating': agg.STD('rating')})
print(grp)

+---------+---------------------+-------------+
| user_id |      std_rating     | mean_rating |
+---------+---------------------+-------------+
|    2    |         0.0         |     4.1     |
|    1    | 0.15000000000000024 |     3.45    |
+---------+---------------------+-------------+
[2 rows x 3 columns]
+3
source

Source: https://habr.com/ru/post/1648577/


All Articles