Skip to content

Commit

Permalink
Merge pull request #108 from tmu-nlp/osada
Browse files Browse the repository at this point in the history
'knock57'
  • Loading branch information
kiyama-hajime authored Jun 10, 2024
2 parents b6640e5 + 40d8ca7 commit ec624f8
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions osada/chapter06/knock57.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"provenance":[],"authorship_tag":"ABX9TyMcG2EMeaB6UHNpyEkURBE4"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"markdown","source":["57\n","52で学習したロジスティック回帰モデルの中で,重みの高い特徴量トップ10と,重みの低い特徴量トップ10を確認せよ."],"metadata":{"id":"iwdLcsj3Q0Rx"}},{"cell_type":"code","source":["#57\n","from sklearn.metrics import *\n","\n","import numpy as np\n","\n","feat = X_train.columns.values\n","ind = [i for i in range(1, 11)]\n","for c, coef in zip(lr.classes_, lr.coef_):\n"," top10 = pd.DataFrame(feat[np.argsort(-coef)[:10]],\n"," columns=[f\"top10 : {c}\"], index=ind)\n"," worst10 = pd.DataFrame(feat[np.argsort(coef)[:10]], columns=[\n"," f\"worst10 : {c}\"], index=ind)\n"," print(f\"{c}'s weight\")\n"," print(top10)\n"," print(worst10)\n"," print(\"---------------------\")"],"metadata":{"id":"gHCmtKtyQzh3"},"execution_count":null,"outputs":[]},{"cell_type":"code","source":["2 update\n","3 google\n","4 study\n","5 says\n","6 billion\n","7 ceo\n","8 china\n","9 data\n","10 gm\n","---------------------\n","m's weight\n"," top10 : m\n","1 ebola\n","2 study\n","3 cancer\n","4 fda\n","5 mers\n","6 drug\n","7 doctors\n","8 cdc\n","9 health\n","10 cases\n"," worst10 : m\n","1 gm\n","2 deal\n","3 facebook\n","4 climate\n","5 ceo\n","6 bank\n","7 sales\n","8 apple\n","9 google\n","10 tv\n","---------------------\n","t's weight\n"," top10 : t\n","1 google\n","2 facebook\n","3 apple\n","4 microsoft\n","5 climate\n","6 heartbleed\n","7 tesla\n","8 tmobile\n","9 googles\n","10 mars\n"," worst10 : t\n","1 shares\n","2 fed\n","3 american\n","4 her\n","5 cancer\n","6 drug\n","7 stocks\n","8 but\n","9 his\n","10 movie\n","---------------------"],"metadata":{"id":"XCyu1HdlRFb0"},"execution_count":null,"outputs":[]}]}

0 comments on commit ec624f8

Please sign in to comment.