ユーザ用ツール

サイト用ツール


linearregression

差分

このページの2つのバージョン間の差分を表示します。

この比較画面へのリンク

次のリビジョン
前のリビジョン
linearregression [2024/07/04 14:46] – 作成 bokupilinearregression [2024/10/12 12:56] (現在) bokupi
行 1: 行 1:
-Scikit learnによる線形回帰モデルによる機械学習コードのテンプレート。+====== 線形回帰モデル ====== 
 + 
 +===== コードテンプレート ===== 
 +Kaggleのtitanic competitionで使った、Scikit learnによる線形回帰モデルによる機械学習コードのテンプレート。
 もう少し直す予定。 もう少し直す予定。
  
-<code>+<code python>
 # 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/python Docker image: https://github.com/kaggle/docker-python # It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
行 53: 行 56:
  
 # Output result to csv. # Output result to csv.
 +# Kaggleで結果を評価させるために、フォーマットを合わせている
 output = pd.DataFrame({'PassengerId': np.ravel(test_passengerId), 'Survived': np.array(np.ravel(Y_pred), dtype=int)}) output = pd.DataFrame({'PassengerId': np.ravel(test_passengerId), 'Survived': np.array(np.ravel(Y_pred), dtype=int)})
 output.to_csv('/kaggle/working/submission.csv', index=False) output.to_csv('/kaggle/working/submission.csv', index=False)
行 58: 行 62:
 print("Finished!") print("Finished!")
 </code> </code>
 +
 +===== 評価方法 =====
 +
 +<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, Y_pred)
 +print("R2 score = ", r2_score_val)
 +</code>
 +
 +titanicのtrain.csvのデータを対象に、単回帰分析で予測した結果の評価結果。
 +かなり厳しい。
 +
 +^説明変数^決定係数^
 +|PClass|0.11456941170524182  |
 +|Age   |0.004299594973638632 |
 +|Fare  |0.06620664646184304  |
 +|SibSp |0.001247678927532414 |
linearregression.1720104369.txt.gz · 最終更新: 2024/07/04 14:46 by bokupi

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki