第3回

第3回演習課題

基礎問題

Q3-1【どのタイプの機械学習?】

応用問題

Q3-2【迷惑メールをみつけよう】

###################  ライブラリのインポート #########################
#いつものPandasとNumPyをインポート
import pandas as pd
import numpy as np

#日本語化MatplotLib
import matplotlib.pyplot as plt
#↓の1行は提出時にはコメントアウトしてください
!pip install japanize-matplotlib
import japanize_matplotlib

# Seabornをインポート
import seaborn as sns

# Pickleをインポート
import pickle
########################### データの取得 ############################
#迷惑メールデータの取得
spam_data = pd.#############################################

############################## 前処理 ################################

#特徴量に指定する列名リスト.データの列名の0~56をスライスで取得
features = spam_data.columns[##:##]

#正解データに指定する列名.データの列名の最後のものをスライスで取得
target = spam_data.columns[##:##]

#特徴量
X = spam_data[features] 

#正解データ
y = spam_data[target]

#X, yのそれぞれを訓練データとテストデータに分ける (訓練:テスト=60:40)
from sklearn.model_selection import train_test_split
X_train, X_test, y_train, y_test = train_test_split(####, ####, #################, random_state=1234)
###################### モデルの選択と学習 #############################

#モデルの選択
from sklearn import tree
model = tree.DecisionTreeClassifier(max_depth=####, random_state=1234)

#モデルの学習(訓練データを使う)
model.#####(#######, ########)

#モデルの表示(オプショナル) 
#tree.plot_tree(model, feature_names=features)
#plt.show()
########################### モデルの評価 ###############################

#分類精度
acc = model.score(#######, #######)
print(f"分類精度: {acc}")

#実際にあっているかどうかを確認してみる (オプショナル)
y_eval = pd.DataFrame()
y_eval["正解"] = y_test[target[0]]
y_eval["予測"] = model.#########(#######)
y_eval["結果"] = (y_eval["正解"] == y_eval["予測"])
print(y_eval)

#混同行列を表示する
from sklearn.metrics import confusion_matrix, ConfusionMatrixDisplay
cm = confusion_matrix(#########, model.##########(########))
print("混同行列:\n", cm)

#プロットする(オプショナル)
#disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=model.classes_)

Q3-3【不動産価格を推定しよう】

発展問題

Q3-4【モデルをチューニングしてみよう】


トップ   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS