Skip to content

Instantly share code, notes, and snippets.

@mkaranasou
Created March 20, 2021 10:51
Show Gist options
  • Save mkaranasou/83b7ec576a931c782156e44bcea1a4b5 to your computer and use it in GitHub Desktop.
Save mkaranasou/83b7ec576a931c782156e44bcea1a4b5 to your computer and use it in GitHub Desktop.
Sample output xj and exploded df for shapley values calculation algorithm
Row: Row(id=964, features=DenseVector([0.886, 0.423, 0.777, 0.777, 0.777, 0.886]))
Calculating SHAP values for "f0"...
+----+-----+-----+-----+-----+-----+-----+-------------------------------------+-----+-----------+------------------------+------------------------------------------------------------------------------+
|id |f0 |f1 |f2 |f3 |f4 |f5 |features |label|is_selected|features_permutations |x |
+----+-----+-----+-----+-----+-----+-----+-------------------------------------+-----+-----------+------------------------+------------------------------------------------------------------------------+
|1677|0.349|0.141|0.162|0.162|0.162|0.349|[0.349,0.141,0.162,0.162,0.162,0.349]|1 |false |[f5, f2, f1, f4, f3, f0]|[[0.349,0.141,0.162,0.162,0.162,0.349], [0.886,0.141,0.162,0.162,0.162,0.349]]|
|2250|0.106|0.938|0.434|0.434|0.434|0.106|[0.106,0.938,0.434,0.434,0.434,0.106]|0 |false |[f0, f4, f5, f3, f1, f2]|[[0.106,0.423,0.777,0.777,0.777,0.886], [0.886,0.423,0.777,0.777,0.777,0.886]]|
|2453|0.801|0.201|0.87 |0.87 |0.87 |0.801|[0.801,0.201,0.87,0.87,0.87,0.801] |0 |false |[f4, f0, f1, f5, f2, f3]|[[0.801,0.423,0.777,0.777,0.87,0.886], [0.886,0.423,0.777,0.777,0.87,0.886]] |
|2509|0.009|0.394|0.831|0.831|0.831|0.009|[0.009,0.394,0.831,0.831,0.831,0.009]|0 |false |[f3, f2, f4, f0, f5, f1]|[[0.009,0.423,0.831,0.831,0.831,0.886], [0.886,0.423,0.831,0.831,0.831,0.886]]|
|2927|0.141|0.68 |0.634|0.634|0.634|0.141|[0.141,0.68,0.634,0.634,0.634,0.141] |0 |false |[f0, f2, f1, f4, f5, f3]|[[0.141,0.423,0.777,0.777,0.777,0.886], [0.886,0.423,0.777,0.777,0.777,0.886]]|
|4823|0.159|0.956|0.888|0.888|0.888|0.159|[0.159,0.956,0.888,0.888,0.888,0.159]|0 |false |[f5, f0, f3, f2, f1, f4]|[[0.159,0.423,0.777,0.777,0.777,0.159], [0.886,0.423,0.777,0.777,0.777,0.159]]|
|65 |0.289|0.975|0.401|0.401|0.401|0.289|[0.289,0.975,0.401,0.401,0.401,0.289]|0 |false |[f3, f5, f0, f1, f4, f2]|[[0.289,0.423,0.777,0.401,0.777,0.289], [0.886,0.423,0.777,0.401,0.777,0.289]]|
|1277|0.884|0.422|0.822|0.822|0.822|0.884|[0.884,0.422,0.822,0.822,0.822,0.884]|0 |false |[f1, f4, f2, f0, f5, f3]|[[0.884,0.422,0.822,0.777,0.822,0.886], [0.886,0.422,0.822,0.777,0.822,0.886]]|
|1360|0.681|0.994|0.336|0.336|0.336|0.681|[0.681,0.994,0.336,0.336,0.336,0.681]|0 |false |[f2, f0, f5, f4, f3, f1]|[[0.681,0.423,0.336,0.777,0.777,0.886], [0.886,0.423,0.336,0.777,0.777,0.886]]|
|3015|0.16 |0.255|0.86 |0.86 |0.86 |0.16 |[0.16,0.255,0.86,0.86,0.86,0.16] |1 |false |[f0, f2, f5, f4, f1, f3]|[[0.16,0.423,0.777,0.777,0.777,0.886], [0.886,0.423,0.777,0.777,0.777,0.886]] |
+----+-----+-----+-----+-----+-----+-----+-------------------------------------+-----+-----------+------------------------+------------------------------------------------------------------------------+
only showing top 10 rows
Exploded df:
+----+-------------------------------------+
|id |features |
+----+-------------------------------------+
|1677|[0.349,0.141,0.162,0.162,0.162,0.349]|
|1677|[0.886,0.141,0.162,0.162,0.162,0.349]|
|2250|[0.106,0.423,0.777,0.777,0.777,0.886]|
|2250|[0.886,0.423,0.777,0.777,0.777,0.886]|
|2453|[0.801,0.423,0.777,0.777,0.87,0.886] |
|2453|[0.886,0.423,0.777,0.777,0.87,0.886] |
|2509|[0.009,0.423,0.831,0.831,0.831,0.886]|
|2509|[0.886,0.423,0.831,0.831,0.831,0.886]|
|2927|[0.141,0.423,0.777,0.777,0.777,0.886]|
|2927|[0.886,0.423,0.777,0.777,0.777,0.886]|
+----+-------------------------------------+
only showing top 10 rowsd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment