2017-01-27 3 views
0

お願いします、この機能が何をしているのか分かりません。pandasライブラリのdata.groupby(cuts).outcome.aggという関数は何ですか?

#group outcomes into bins of similar probability 
    bins = np.linspace(0, 1, 20) 
    cuts = pd.cut(prob, bins) 
    print(cuts) 
    binwidth = bins[1] - bins[0] 

    #freshness ratio and number of examples in each bin 
    cal = data.groupby(cuts).outcome.agg(['mean', 'count']) 
    print(cal['count']) 
    print(cal['mean']) 
    cal['pmid'] = (bins[:-1] + bins[1:])/2 
    cal['sig'] = np.sqrt(cal.pmid * (1 - cal.pmid)/cal['count']) 

    #the calibration plot 
    ax = plt.subplot2grid((3, 1), (0, 0), rowspan=2) 
    p = plt.errorbar(cal.pmid, cal['mean'], cal['sig']) 
    plt.plot(cal.pmid, cal.pmid, linestyle='--', lw=1, color='k') 
    plt.ylabel("Empirical Fraction") 
+0

APIのドキュメントはありませんか? – csmckelvey

答えて

0

dataoutcomeという名前の列を含むDataFrameです: は、ここでは、コードのコンテキストです。あなたのコードの凸部は、次のとおりです。「カット」欄(further reference)のエントリに基づいて

  1. グループデータ:これは何

    cal = data.groupby(cuts).outcome.agg(['mean', 'count']) 
    

    は順番に、です。

  2. 「結果」列に対応するSeriesGroupByを取得します。
  3. SeriesGroupBy(例:hereを参照)の各グループに「平均」と「カウント」の2つの列が適用されたDataFrameを作成します。
  4. 変数をcalに割り当てます。
関連する問題