scikit-learn を使って線形回帰
https://gyazo.com/619c803729900b609a39d43e28331661
https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html
こちらの記事を参考にさせていただきました。
Scikit-learn で線形回帰
こちらの記事ではボストンの郊外住宅価格を使用していましたが、どうも最近のデータセット内には含まれていないようなので、(倫理的な問題?)代わりにカリフォルニアのデータを使用します。
code:python
from sklearn.datasets import fetch_california_housing
housing = fetch_california_housing()
データセットの説明はこちらにあります。
こちらをやってみる。
データを描画するのに、 seaborn を使った方が楽かもしれない。
散布図 pairplot
標準化するライブラリ
https://note.nkmk.me/python-list-ndarray-dataframe-normalize-standardize/
pandas で、たとえば文字のカテゴリをカラムに分割するときに pd.get_dummies 関数が使える。
matplotlib で縦線や横線を引くのであれば、 hline や vline を使用する。
https://py-memo.com/python/matplotlib-vlines-hlines/
matplotlib で単純にグラフを重ねるのであれば、 plot にそのまま宣言してしまえばいい。
code:python
plt.figure(figsize=(10, 8))
plt.scatter(lin_train_pred, y_train, alpha=0.4)
plt.plot(0, lin_train_pred.max(), 0, lin_train_pred.max(), color="red")
plt.xlabel('Prediction')
plt.ylabel('Residual')
plt.show()
#ml