Code Monkey home page Code Monkey logo

machinelearning-book's People

Contributors

shimitaku avatar shimizutakuya avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

machinelearning-book's Issues

4.2 勾配ブースティング決定木の例題における年齢の分岐条件について (P.151~)

いつもお世話になっております。

とても中身が濃い本で、大変勉強になっております。
おかげさまで、ずいぶん機械学習に親しみを持てるようになりました。

さて、4.2)勾配ブースティング決定木の例題に登場する決定木(151ページ以降の図4.6~4.9)に関する質問です。

分岐条件に、年齢が使われていますが、各年齢の数値がどこから出てきたものなのか、教えてください。
例えば、図4.6は年齢≦22となっておりますが、調査対象者の中に、22歳の人がいないため、
どこから出てきた数字なのかを知りたいです(調査対象者Bの32歳が正しい条件なのでは?とも思料しますが、
勘違いでしたら、ご指摘ください…)。

20200113_aibook_qa

お手数をお掛け致しますが、
どうぞよろしくお願い致します。

リスト5.2 pandas_profilingを使ったIrisのデータチェック

pandas_profilingのバージョンが3.0.0の場合、以下の修正が必要でした
(pandas_profilingのVersionUPの為か、以下の処理でも図5.4 と同じ表示表示になりませんでした。例:Rejected が表示されない

1.pandasのバージョンアップ(pandas_profiling処理中にエラーが出る場合。必要最低限のバージョンはわかりませんでした)
2.変数名の修正(outputfile → output_file)
<Before>
profile.to_file(outputfile="profile.html")
<After>
profile.to_file(output_file="profile.html")

<追記>
pandas_profilingのバージョンが3.0以上の場合、下記のコードで同様な情報表示が可能でした

# データのprofileを作成
from pandas_profiling import ProfileReport

profile = ProfileReport(df)
profile

2.4 ロジステックス回帰によるクラス分類 リスト2.8 (P044)

2.4 ロジステックス回帰によるクラス分類 リスト2.8が、【matplotlib:3.3.2】では上手く動かなかったので、対策と合わせて投稿させていただきます。
参考になれば幸いです。

plt.scatter(X[label == 0], Y[label == 0], marker=',', s=30, c='red', edgecolors=' ', label='0:withdraw')
を【matplotlib:3.3.2】で動かすと、以下のエラーが出ました、
ValueError: Expected 2-dimensional array, got 1

【matplotlib:3.3.2】では、edgecolors=' ' がブランクだとエラーになるようです。
edgecolors='blue'と色名を記載すると、正常に動作しました。

<Before>
plt.scatter(X[label == 1], Y[label == 1], marker='^', s=30,c='blue', edgecolors='', label='1:continue')
plt.scatter(X[label == 0], Y[label == 0], marker=',', s=30,c='red', edgecolors='', label='0:withdraw')
<After>
plt.scatter(X[label == 1], Y[label == 1], marker='^', s=30,c='blue', edgecolors='blue', label='1:continue')
plt.scatter(X[label == 0], Y[label == 0], marker=',', s=30,c='red', edgecolors='red', label='0:withdraw')

ガウス混合モデルの結果の可視化の箇所において,サンプルプログラムに誤りがありました.

第3章のガウス混合モデルによるクラスタリングの結果を可視化する際に,
サンプルプログラムをそのまま実行すると,書籍に載っている図のような色分けになりませんでした.
Figure_1

おそらく,引数cに渡しているラベル配列の問題ではないかと思います.
plt.scatter(X_norm[:, 0], X_norm[:, 1], c=y, cmap='brg')
plt.scatter(X_norm[:, 0], X_norm[:, 1], c=kmean_y_pred, cmap='brg')
plt.scatter(X_norm[:, 0], X_norm[:, 1], c=gmm_y_pred, cmap='brg')

ご確認よろしくお願いいたします.

2.6 決定木によるクラス分類 リスト2.18(P69):”graphviz”のインストール

import graphviz
上記Importの際、エラーが出る場合は、graphvizがインストールがされていないと考えpip install graphvizを行うが、これでは決定木が表示されず、エラーが出力される(インストール時にエラーは出ない)

graphvizをインストールする場合は、以下の手順で行う

1.apt-getコマンドでパッケージ本体をインストールする
apt-get update
apt-get install graphviz

2.pipコマンドを使いpython用のラッパーをインストールする
pip install graphviz

リスト5.2 Irisのデータチェックを行う実装コード

いつもお世話になっております。

とても分かりやすい本で、勉強させていただきました。
未来機械学習の勉強も続けそうに感じしております。

さて、掲題の件ですが、本に記載しているコードをGoogle colaboratoryに実行しましたが、以下のエラーを表示してしまいました。

リスト5.2 Irisのデータチェックを行う実装コード
image

エラーメッセージ:

/usr/local/lib/python3.6/dist-packages/pandas_profiling/describe.py in describe(df, bins, check_correlation, correlation_threshold, correlation_overrides, check_recoded, pool_size, **kwargs)
390 if name not in names:
391 names.append(name)
--> 392 variable_stats = pd.concat(ldesc, join_axes=pd.Index([names]), axis=1)
393 variable_stats.columns.names = df.columns.names
394
TypeError: concat() got an unexpected keyword argument 'join_axes'

Googleでエラー発生した原因はpandas_proflingのversionに問題があるようです。

Google colaboratoryで実行できるようにコードを下記のように修正しました。

!pip` install -U pandas_profiling # pandas-profilingのパッケージをインストール
#データのprofileを作成
import pandas_profiling as pdp
from IPython.display import HTML
profile = pdp.ProfileReport(df)
profile.to_file("profile.html")
HTML(filename='profile.html')

多分、本を作成した当時より、現在は使用しているパッケージのバージョンが使えなくなりましたではないでしょうか、自分の認識齟齬もあると思います。

お手数をおかけして申し訳ございません、
どうぞよろしくお願い致します。

4.4 t-SNEによる次元圧縮 リスト4.8

sklearn の仕様変更

必要なライブラリのインポート にある、
"from sklearn.datasets.samples_generator import make_s_curve"
を走らせると、
ModuleNotFoundError: No module named 'sklearn.datasets.samples_generator'
とエラーが出ます。

scikit-learnの最新バージョンでは、表記が変わったそうで、
"from sklearn.datasets import make_s_curve"
でインポートできました。

3-2 主成分分析(PCA) リスト3.3について

3-2 主成分分析(PCA) リスト3.3について、
固有ベクトルの軸のプロットですが、少し傾きがおかしいので、
計算方法が誤っているのではないかと思い、投稿させていただきます。

標準化の逆変換は、x=μ+σx' となるのでsc.mean_を加算する必要はないと思います。
また固有ベクトルは列ベクトルなので第1成分は[:,0]で渡すと思います(はまる人が多いらしいですが)。

以下が修正案(の一つ)と思います。5倍の部分は線分の長さを左右に広げているだけです。
pca_point1 = sc.inverse_transform(5.*pca.components_[:,0])
pca_point2 = sc.inverse_transform(-5.*pca.components_[:,0])

たとえば、共分散行列のSxy^2を20から-20にして負の相関にしてみてください。
元の計算では固有ベクトルの軸がさらに変なところに引かれてしまうのですが、
修正案では20でも-20でも、もっともらしい場所になります。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.