Help us understand the problem. What is going on with this article?

初めてのLinearRegressionモデル作成

モデル作成から数値予測までの過程の概要をざっとつかみたい!

回帰分析とは?

説明したい量(目的変数)を他の量(説明変数)を用いて表現すること
その際の方程式が必ずしも直線にはならないので、回帰分析と呼ぶ!(直線の場合は、線形回帰)

ピザの直径25cmの時、ピザの値段は?

環境:Google Colaboratory

x=[[12],[16],[20],[28],[36]] #ピザの直径
y = [[700],[900],[1300],[1750],[1800]] #ピザの値段
from sklearn.linear_model import LinearRegression
model = LinearRegression()#1.モデルの指定
model.fit(x,y)#2.学習
import numpy as np
#n×1ベクトルに変換する必要があるらしい...
#その時、reshape()の中身を-1とすると、自動的にnumpyが判断してくれるらしい(便利だ)
price = model.predict(np.array([25]).reshape(-1, 1)) # 3.予測(25㎝を代入)
print('25 cm pizza should cost: $%s'%price[0][0])
出力.
25 cm pizza should cost: $1416.9181034482758

この出力結果の精度がどれだけ正確か知りたい!

# テストデータを作成
x_test = [[16],[18],[22],[32],[24]]
y_test = [[1100],[850],[1500],[1800],[1100]]

score = model.score(x_test, y_test)
print("r-squared:",score)
出力.
r-squared: 0.6620052929422553

結果

モデルの精度は0.662と出たが、初めてにしては満足のいく結果となった。
次回は、精度をあげるために単回帰ではなく説明変数を増やして重回帰によって回帰分析していきたい!

pi-to
見習い くそあほ大学生
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした