-2

I have a dataframe of the format cp= [cars['car_models']=="chevy"] How is it possible to get the average of cp?

have looked everywhere for how to this this. thanks for the help

  • Please be more specific. Are you trying to compute the average of all values in the SFrame (I assume it's an SFrame, right?), the average of each column, the average of each row? Based on the way you constructed `cp`, at least one column will contain strings, so the average isn't meaningful for that column, so how do you want to deal with that? – papayawarrior May 11 '16 at 17:23

1 Answers1

0

As @papayawarrior said, SFrames don't have averages. SArrays (of type float/int) might have these.

>>> sf = gl.SFrame({"x":[1,2,3]}) # SFrame with a single column (SArray) x.
>>> sf["x"].mean() # sf["x"] grabs the SArray x, then we take its average.
2.0

If you want the root mean square error, you should also have two SArrays (maybe in the same SFrame). I don't know what a "root mean squared value" is.

import graphlab as gl

cars = gl.SFrame({
    "car_models": ["chevy", "ford", "chevy"],
    "targets": [1, 2, 3],
    "predictions": [7, 9, 8]
    })

cp = cars[cars["car_models"] == "chevy"]
rmse = gl.evaluation.rmse(cp["targets"], cp["predictions"])

The rmse in this example is 5.522680508593631 .

Guy Rapaport
  • 318
  • 3
  • 11