Menu
CoddyTech

振り返り:ローンの判断

CoddyのMachine Learningジャーニー「教師あり学習」セクションの一部。レッスン 31/58。

challenge icon

チャレンジ

中級

この章で予告した農業融資のことを覚えていますか?あるマイクロローン基金は、農家に説明できる決定木を求めています。スターターコードは、過去の融資データを分割します。

  1. 深さ1から順に木を成長させ(random_state=0)、各テスト精度を表示します。直前の深さより良くならなかった最初の深さで停止します。
  2. 精度が向上した最後の深さを採用し、それとその木の質問を表示します。
  3. 以下のように、最も重要な特徴量を2つ表示します。

別の基金の場合:

Depth 1: test accuracy 0.650
Depth 2: test accuracy 0.850
Depth 3: test accuracy 0.833
Keep depth 2
|--- savings_usd <= 154.50
|   |--- earlier_loans <= 0.50
|   |   |--- class: 0
|   |--- earlier_loans >  0.50
|   |   |--- class: 1
|--- savings_usd >  154.50
|   |--- earlier_loans <= 0.50
|   |   |--- class: 1
|   |--- earlier_loans >  0.50
|   |   |--- class: 1

Most important: savings_usd (0.563)
Next: earlier_loans (0.437)

自分で試してみよう

import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeClassifier, export_text

# 小規模農家への過去のマイクロローン:repaid の 1 は、融資が全額返済されたことを意味します
loans = pd.read_csv("loans.csv")
features = ["amount_usd", "income_usd", "years_farming", "earlier_loans", "savings_usd", "group_size"]
X_train, X_test, y_train, y_test = train_test_split(loans[features], loans["repaid"], test_size=0.25, random_state=0)

# 以下にコードを書いてください

教師あり学習のすべてのレッスン

自分で練習してみよう: Pythonオンラインコンパイラ