ASP YOK
ASP YOK

Reputation: 131

Regression with Big Query ML

I tried a linear regression with Big Query.

therefor I used test data:

nr1 nr2 x
1   1   1
2   2   2
3   3   3
4   4   4
5   5   5
6   6   6
7   7   7
8   8   8
9   9   9
10  10  10
11  11  11
12  12  12

With the following query i created a model.

CREATE MODEL `regression_model_9`
OPTIONS
  (model_type='linear_reg',
    input_label_cols=['x']) AS
SELECT
 nr1,
 nr2,
 x
FROM
  `reg_test`  

After that I evaluate the model and want to make a prediction, like described here: https://cloud.google.com/bigquery/docs/bigqueryml-analyst-start So what I have to do to get predict a 13?

With the following I get "Query returned zero records.....

SELECT
  x
FROM
  ML.PREDICT(MODEL `regression_model_9`,
    (
SELECT
x,
 nr1,
 nr2
FROM
  `reg_test`  
  where nr1=13 
  ))

Upvotes: 1

Views: 204

Answers (1)

Mikhail Berlyant
Mikhail Berlyant

Reputation: 172944

... what I have to do to get predict a 13?

#standardSQL
SELECT *
FROM ML.PREDICT(MODEL `yourproject.yourdataset.regression_model_9`, 
  (SELECT 13 nr1, 13 nr2))     

with result as something like below

Row     predicted_x         nr1     nr2  
1       12.999999982559942  13      13   

Upvotes: 1

Related Questions