linearregression
差分
このページの2つのバージョン間の差分を表示します。
次のリビジョン | 前のリビジョン | ||
linearregression [2024/07/04 14:46] – 作成 bokupi | linearregression [2024/10/12 12:56] (現在) – bokupi | ||
---|---|---|---|
行 1: | 行 1: | ||
- | Scikit learnによる線形回帰モデルによる機械学習コードのテンプレート。 | + | ====== 線形回帰モデル ====== |
+ | |||
+ | ===== コードテンプレート ===== | ||
+ | Kaggleのtitanic competitionで使った、Scikit learnによる線形回帰モデルによる機械学習コードのテンプレート。 | ||
もう少し直す予定。 | もう少し直す予定。 | ||
- | < | + | < |
# This Python 3 environment comes with many helpful analytics libraries installed | # This Python 3 environment comes with many helpful analytics libraries installed | ||
# It is defined by the kaggle/ | # It is defined by the kaggle/ | ||
行 53: | 行 56: | ||
# Output result to csv. | # Output result to csv. | ||
+ | # Kaggleで結果を評価させるために、フォーマットを合わせている | ||
output = pd.DataFrame({' | output = pd.DataFrame({' | ||
output.to_csv('/ | output.to_csv('/ | ||
行 58: | 行 62: | ||
print(" | print(" | ||
</ | </ | ||
+ | |||
+ | ===== 評価方法 ===== | ||
+ | |||
+ | <code python> | ||
+ | from sklearn.metrics import r2_score | ||
+ | |||
+ | # 線形回帰モデル作成(略) | ||
+ | |||
+ | # test.csvは正解が分からないので、train.csvのデータで評価する | ||
+ | Y_pred = model.predict(train_X) | ||
+ | |||
+ | # 決定係数による評価 | ||
+ | r2_score_val = r2_score(train_Y, | ||
+ | print(" | ||
+ | </ | ||
+ | |||
+ | titanicのtrain.csvのデータを対象に、単回帰分析で予測した結果の評価結果。 | ||
+ | かなり厳しい。 | ||
+ | |||
+ | ^説明変数^決定係数^ | ||
+ | |PClass|0.11456941170524182 | ||
+ | |Age | ||
+ | |Fare |0.06620664646184304 | ||
+ | |SibSp |0.001247678927532414 | |
linearregression.1720104369.txt.gz · 最終更新: 2024/07/04 14:46 by bokupi