1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

【機械学習初心者】部屋の広さから家賃を予測

Last updated at Posted at 2021-08-27

##はじめに

機械学習の知識を使って財務シュミレーションを簡潔に行いたいと思いPythonで実装してみました。

##対象者

  • 機械学習初心者
  • 財務シュミレーションなど行いたい方

##開発した時の環境

version 
Python 3.8.5
Homebrew 3.0.2 
jupyter notebook

##単回帰分析の実装

部屋の広さx家賃がy万円

##まず取り込みたいCSVデータをインポートします

import pandas as pd
df = pd.read_csv('sample.csv')

#グラフ描画ツールMatplotlib

import matplotlib.pyplot as plt

#xとyの散布図プロット

plt.scatter(x, y)
plt.show()

Screenshot 2021-08-16 at 14.24.27.png

#予測値
xx = x*x
xy = x*y
a = xy.sum()/xx.sum()

plt.scatter(x,y, label='y')
#学習フェーズ
plt.plot(x, a*x, label='y_hat', color ='red')
plt.legend()
plt.show

Screenshot 2021-08-18 at 12.43.02.png

#予測値
x_new = 1000 #○○平米の部屋
mean = df.mean()
mean['x']

xc = x_new - mean['x']
xc 

yc = a*xc

y_hat = a*xc + mean['y']


def predict(x):
    
 a = 30069.022519284063
 xm = 37.622219999999999
 ym = 121065.0
 xc = x - xm 
 y_hat = a*xc + ym

 return y_hat  
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?