Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

When I try to use batch prediction through my time series modle convert Numeric and String Error

 

I used Vertex AI to create a time series forecasting model.
When performing Batch Prediction, the prediction results need to be uploaded to a BigQuery table.
In the BigQuery table, there is a column nameBenefit_per_order, which is of type FLOAT. However, MY model requires the input to be of type STRING.

Even if I tried changing all the values in the Benefit_per_order column to meaningless strings (e.g., "N/A"), the issue persists, and the prediction cannot proceed successfully.


The error message I encountered indicates a data type mismatch: the model requires the input to be of typeSTRING, but the column type in the BigQuery table remains FLOAT. Even if I modified the values in the column, the data type itself has not changed.

Google Cloud Deploy Batch Prediction Error.png

0 1 209
1 REPLY 1

Hi @zhenyuzhuang,

Welcome to Google Cloud Community!

Even though you modified the values in the Benefit_per_order column, this will still not affect its data type.

Below are the possible solution to convert your column’s data type to string:

  1. You can refer to these steps on Stack Overflow. I have tried this and it works fine.
  2. You could also consider using the CAST function and load your data into a new table in BigQuery. Before applying this, be aware that this requires a full table scan which can significantly increase cost, particularly for large tables. Below is the sample query:
CREATE TABLE `mydataset.newtable` AS(
SELECT
field1,
field2,
CAST(Benefit_per_order AS STRING) as Benefit_per_order 
FROM `mydataset.yourtable`)

  Alternatively, you can create a materialized view using the CAST function instead of creating a table. Below is the sample query:

CREATE MATERIALIZED VIEW `mydataset.newtable` AS(
SELECT
field1,
field2,
CAST(Benefit_per_order AS STRING) as Benefit_per_order 
FROM `mydataset.yourtable`)

To learn more about the materialized view, review this documentation.

        3. Another approach to consider is using SET DATA TYPE DDL statements, but this approach is not suitable for your case since the only supported data type conversions are the following: 

  • INT64 to NUMERIC, BIGNUMERIC, FLOAT64
  • NUMERIC to BIGNUMERIC, FLOAT64

Was this helpful? If so, please accept this answer as “Solution”. If you need additional assistance, reply here within 2 business days and I’ll be happy to help.