@@ -1043,8 +1043,8 @@ def list_models(self, project=None, region=None):
1043
1043
def create_model (self , model_display_name , dataset = None ,
1044
1044
dataset_display_name = None , dataset_name = None ,
1045
1045
train_budget_milli_node_hours = None , project = None ,
1046
- region = None ):
1047
- """Create a model. This will train your model on the given dataset.
1046
+ region = None , input_feature_column_specs_included = None , input_feature_column_specs_excluded = None ):
1047
+ """Create a model. This will train your model on the given dataset.
1048
1048
1049
1049
Example:
1050
1050
>>> from google.cloud import automl_v1beta1
@@ -1057,7 +1057,6 @@ def create_model(self, model_display_name, dataset=None,
1057
1057
>>>
1058
1058
>>> m.result() # blocks on result
1059
1059
>>>
1060
-
1061
1060
Args:
1062
1061
project (Optional[string]):
1063
1062
If you have initialized the client with a value for `project`
@@ -1085,11 +1084,15 @@ def create_model(self, model_display_name, dataset=None,
1085
1084
The `Dataset` instance you want to train your model on. This
1086
1085
must be supplied if `dataset_display_name` or `dataset_name`
1087
1086
are not supplied.
1088
-
1087
+ input_feature_column_specs_included(Optional[string]):
1088
+ The list of the names of the columns you want to include to train
1089
+ your model on.
1090
+ input_feature_column_specs_excluded(Optional[string]):
1091
+ The list of the names of the columns you want to exclude and
1092
+ not train your model on.
1089
1093
Returns:
1090
1094
A :class:`~google.cloud.automl_v1beta1.types._OperationFuture`
1091
1095
instance.
1092
-
1093
1096
Raises:
1094
1097
google.api_core.exceptions.GoogleAPICallError: If the request
1095
1098
failed for any reason.
@@ -1101,26 +1104,56 @@ def create_model(self, model_display_name, dataset=None,
1101
1104
raise ValueError ('\' train_budget_milli_node_hours\' must be a '
1102
1105
'value between 1,000 and 72,000 inclusive' )
1103
1106
1107
+ if input_feature_column_specs_excluded not in [None , []] and input_feature_column_specs_included not in [None , []]:
1108
+ raise ValueError ('\' cannot set both input_feature_column_specs_excluded\' and '
1109
+ '\' input_feature_column_specs_included\' ' )
1110
+
1111
+
1104
1112
dataset_name = self .__dataset_name_from_args (dataset = dataset ,
1105
1113
dataset_name = dataset_name ,
1106
1114
dataset_display_name = dataset_display_name ,
1107
1115
project = project ,
1108
1116
region = region )
1109
-
1117
+ tables_model_metadata = {
1118
+ 'train_budget_milli_node_hours' : train_budget_milli_node_hours
1119
+ }
1110
1120
dataset_id = dataset_name .rsplit ('/' , 1 )[- 1 ]
1121
+ columns = [s for s in self .list_column_specs (dataset = dataset , dataset_name = dataset_name , dataset_display_name = dataset_display_name )]
1122
+
1123
+ final_columns = []
1124
+ if input_feature_column_specs_included :
1125
+ column_names = [a .display_name for a in columns ]
1126
+ if not (all (name in column_names for name in input_feature_column_specs_included )):
1127
+ raise ValueError ('invalid name in the list' '\' input_feature_column_specs_included\' ' )
1128
+ for a in columns :
1129
+ if a .display_name in input_feature_column_specs_included :
1130
+ final_columns .append (a )
1131
+
1132
+ tables_model_metadata .update (
1133
+ {'input_feature_column_specs' : final_columns }
1134
+ )
1135
+ elif input_feature_column_specs_excluded :
1136
+ for a in columns :
1137
+ if a .display_name not in input_feature_column_specs_excluded :
1138
+ final_columns .append (a )
1139
+
1140
+ tables_model_metadata .update (
1141
+ {'input_feature_column_specs' : final_columns }
1142
+ )
1143
+
1111
1144
request = {
1112
1145
'display_name' : model_display_name ,
1113
1146
'dataset_id' : dataset_id ,
1114
- 'tables_model_metadata' : {
1115
- 'train_budget_milli_node_hours' : train_budget_milli_node_hours
1116
- }
1147
+ 'tables_model_metadata' : tables_model_metadata
1117
1148
}
1118
1149
1150
+
1119
1151
return self .client .create_model (
1120
1152
self .__location_path (project = project , region = region ),
1121
1153
request
1122
1154
)
1123
1155
1156
+
1124
1157
def delete_model (self , model = None , model_display_name = None ,
1125
1158
model_name = None , project = None , region = None ):
1126
1159
"""Deletes a model. Note this will not delete any datasets associated
0 commit comments