How to create a dataset with google cloud AutoML - python

Silly question, but I'm new to Python and Google Cloud. I'm trying to predict customer-lifetime-value with google cloud automl_v1beta1, the code is here
from google.cloud.automl_v1beta1 import AutoMlClient, PredictionServiceClient
from google.cloud_v1beta1 import automl
client = AutoMlClient.from_service_account_file(keyfile_name)
location_path = f"projects/{project_id}/locations/us-central1"
dataset_display_name = automl_dataset
# create dataset
create_dataset_response = client.create_dataset(
parent=location_path,
dataset={'display_name': dataset_display_name, 'tables_dataset_metadata': {}})
and I received the following errors:
\
Traceback (most recent call last):
File "/home/tensorflow-lifetime-value/clv_automl/test1.py", line 220, in <module>
main()
File "/home/tensorflow-lifetime-value/clv_automl/test1.py", line 193, in main
model_name = create_automl_model(client,
File "/home/tensorflow-lifetime-value/clv_automl/test1.py", line 48, in
create_automl_model
create_dataset_response = client.create_dataset(
File "/home/.local/lib/python3.9/site-packages/google/cloud/automl_v1/services/auto_ml/client.py", line 623, in create_dataset
request.dataset = dataset
File "/usr/local/lib/python3.9/dist-packages/proto/message.py", line 757, in __setattr__
pb_value = marshal.to_proto(pb_type, value)
File "/usr/local/lib/python3.9/dist-packages/proto/marshal/marshal.py", line 211, in to_proto
pb_value = rule.to_proto(value)
File "/usr/local/lib/python3.9/dist-packages/proto/marshal/rules/message.py", line 36, in to_proto
return self._descriptor(**value)
ValueError: Protocol message Dataset has no "tables_dataset_metadata" field.

I got the same error using your code when I used google-cloud-automl<=0.1.2. Your error will be fixed if you use google-cloud-automl>=0.1.2. But I suggest to always install the latest version by doing pip install --upgrade google-cloud-automl to maximize the latest updates from Google Cloud.

Related

TypeError: Parameter to MergeFrom() must be instance of same class: expected google.datastore.v1.Key.PathElement got PathElement

I am trying to push the data to GCP DataStore, The below code snippet works fine in Jupyter Notebook but it is throwing error in VS Code.
def load_data_json(self, kind_name, data_with_qp_ID, qp_id):
#Load the data in JSON format to upload into the DataStore
data_with_qp_ID_as_JSON = self.convert_DF_to_JSON(data_with_qp_ID, qp_id)
#Loop to iterate through the JSON format and upload into the GCS Storage
for data in data_with_qp_ID_as_JSON.keys():
with self.client.transaction():
incomplete_key = self.client.key(kind_name)
task = datastore.Entity(key=incomplete_key)
task.update(data_with_qp_ID_as_JSON[data])
self.client.put(task)
return 'Ingestion Successful - Data Store Repository'
I have defined the name of the bucket in "Kind Name", data_with_qp_id is a pandas dataframe, qp_id is the name of the column name in pandas. Please see the error message that I get below,
Traceback (most recent call last):
File "/Users/ajaykrishnan/Desktop/Projects/Sprint 3/Data Migration/DataMigration_v1.1/main2.py", line 139, in <module>
write_datastore_db.load_data_json(ds_kindname, bookmarks_data_with_qp_ID, qp_id)
File "/Users/ajaykrishnan/Desktop/Projects/Sprint 3/Data Migration/DataMigration_v1.1/pkg/repository/ds_repository.py", line 50, in load_data_json
self.client.put(task)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/client.py", line 597, in put
self.put_multi(entities=[entity], retry=retry, timeout=timeout)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/client.py", line 634, in put_multi
current.put(entity)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/transaction.py", line 315, in put
super(Transaction, self).put(entity)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/batch.py", line 227, in put
_assign_entity_to_pb(entity_pb, entity)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/batch.py", line 373, in _assign_entity_to_pb
bare_entity_pb = helpers.entity_to_protobuf(entity)
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/helpers.py", line 208, in entity_to_protobuf
key_pb = entity.key.to_protobuf()
File "/opt/anaconda3/lib/python3.9/site-packages/google/cloud/datastore/key.py", line 298, in to_protobuf
key.path.append(element)
TypeError: Parameter to MergeFrom() must be instance of same class: expected google.datastore.v1.Key.PathElement got PathElement.
My environment is as follows,
Mac OS Monterey V12.06
Python - Conda 3.9.12
I was able to clear this error. It was an issue with Protobuf library that my environment was using. I downgraded the version of protobuf from 4.x.x to 3.20.1 and it worked.

KeyError: 'observation' while trying out multi agent reinforcement learning with OpenAI stable-baselines3 and gym

I was trying to use hungry-geese gym here to train PPO:
from kaggle_environments import make
from stable_baselines3 import PPO
directions = {0:'EAST', 1:'NORTH', 2:'WEST', 3:'SOUTH'}
loaded_model = PPO.load('logs\\dqn2ppo_nonvec\\model')
def agent_ppo(obs, config):
a = directions[loaded_model.predict(obs)[0]]
return a
env = make('hungry_geese',debug=True)
env.run([agent_ppo,'agent_bfs.py'])
env.render(mode="ipython")
But my game was getting played for only one step. After running with debug ON I got following trace:
Traceback (most recent call last):
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\kaggle_environments\agent.py", line 151, in act
action = self.agent(*args)
File "<ipython-input-29-faad97d317d6>", line 5, in agent_ppo
a = directions[loaded_model.predict(obs)[0]]
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\base_class.py", line 497, in predict
return self.policy.predict(observation, state, mask, deterministic)
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\policies.py", line 262, in predict
observation = ObsDictWrapper.convert_dict(observation)
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\vec_env\obs_dict_wrapper.py", line 68, in convert_dict
return np.concatenate([observatio I was trying to use hungry-geese gym [here](https://www.kaggle.com/victordelafuente/dqn-goose-with-stable-baselines3-pytorch#) to train PPO. But my game was getting played for only one step. After running with debug ON I got following trace:
Traceback (most recent call last):
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\kaggle_environments\agent.py", line 151, in act
action = self.agent(*args)
File "<ipython-input-29-faad97d317d6>", line 5, in agent_ppo
a = directions[loaded_model.predict(obs)[0]]
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\base_class.py", line 497, in predict
return self.policy.predict(observation, state, mask, deterministic)
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\policies.py", line 262, in predict
observation = ObsDictWrapper.convert_dict(observation)
File "c:\users\crrma\.virtualenvs\hungry_geese-ept5y6nv\lib\site-packages\stable_baselines3\common\vec_env\obs_dict_wrapper.py", line 68, in convert_dict
return np.concatenate([observation_dict[observation_key], observation_dict[goal_key]], axis=-1)
KeyError: 'observation'
So I debuged a bit more in vscode. As can be seen in below screenshot, both observation and desired_goal keys are not present in observation_dict.
Also this is how I debuged to above call:
Am I using API incorrectly for this to occur (am new to the API)? (or this can be a bug, which I feel highly unlikely.)
Colab notebook and model

problems when I try to run the neural network from github

I am trying to run the following github project:
https://github.com/jeffgreenca/laughr
I can run the command: pipenv run python laughr.py --help
but when I ask to mute a laugh from an audio file I get the following error:
Traceback (most recent call last):
File "laughr.py", line 292, in <module>
model=localModel)
File "laughr.py", line 202, in do_mute_laughs
laughr.remove_laughs(sourceFile, outFile)
File "laughr.py", line 147, in remove_laughs
rc.laughs = self.model.predict(rc.build_features())
File "laughr.py", line 73, in build_features
self.raw = self.y.T[0][i * chunkLen:(i + 1) * chunkLen]
IndexError: invalid index to scalar variable.
I think it may be a wrong version of the tensorflow or keras that I am using, but I have no idea which one is right. thanks for listening.

Getting a TypeError with Python quandl.get: raise_on_status

Im following a tutorial on ML and quandl and have imported quandl and dependencies for python3. When I run
import quandl
data = quandl.get("EIA/PET_RWTC_D")
print(data.head())
I have a quandl account and this code is from the quandl python docs since I wanted to make sure the tutorial was not wrong (https://www.youtube.com/watch?v=JcI5Vnw0b2c&list=PLQVvvaa0QuDfKTOs3Keq_kaG2P55YRn5v&index=2) (I made sure it was lowercase quandl for import since it differed due to the posted date of the video), I also tried with my api_key and using that arg in quandl.get()
I get the error:
Traceback (most recent call last):
File "ml_regression1.py", line 4, in <module>
quandl.get("EIA/PET_RWTC_D", authtoken="MyAuthTokenPlaceHolder")
File "/usr/local/lib/python3.5/dist-packages/quandl/get.py", line 48, in get
data = Dataset(dataset_args['code']).data(params=kwargs, handle_column_not_found=True)
File "/usr/local/lib/python3.5/dist-packages/quandl/model/dataset.py", line 47, in data
return Data.all(**updated_options)
File "/usr/local/lib/python3.5/dist-packages/quandl/operations/list.py", line 14, in all
r = Connection.request('get', path, **options)
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 38, in request
return cls.execute_request(http_verb, abs_url, **options)
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 42, in execute_request
session = cls.get_session()
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 58, in get_session
adapter = HTTPAdapter(max_retries=cls.get_retries())
File "/usr/local/lib/python3.5/dist-packages/quandl/connection.py", line 74, in get_retries
raise_on_status=False)
TypeError: __init__() got an unexpected keyword argument 'raise_on_status'
Any help would be great, thank you.
pip3 install --upgrade urllib3 solved the problem for me (urllib3 was not up to date).
see also https://stackoverflow.com/a/53375266/8496767

unable to start carbon-graphite on ubuntu 12.04

I am working on Sensu and graphite. Where Sensu server sends the data in the JSON format to graphite server to draw graphs of the various metrics and parameters.
I am getting following error while trying to start carbon. I have pasted the error log and trace back here. I am not able to find the solution in the internet. I tried googling almost everything.
I have enabled AMQP to read the metrics from the rabbitMQ server.
Traceback (most recent call last):
File "./carbon-cache.py", line 30, in <module>
run_twistd_plugin(__file__)
File "/opt/graphite/lib/carbon/util.py", line 90, in run_twistd_plugin
config.parseOptions(twistd_options)
File "/usr/local/lib/python2.7/dist-packages/twisted/application/app.py", line 614, in parseOptions
usage.Options.parseOptions(self, options)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/usage.py", line 266, in parseOptions
self.subOptions.parseOptions(rest)
File "/usr/local/lib/python2.7/dist-packages/twisted/python/usage.py", line 276, in parseOptions
self.postOptions()
File "/opt/graphite/lib/carbon/conf.py", line 188, in postOptions
program_settings = read_config(program, self)
File "/opt/graphite/lib/carbon/conf.py", line 497, in read_config
settings.readFrom(config, section)
File "/opt/graphite/lib/carbon/conf.py", line 137, in readFrom
value = parser.getboolean(section, key)
File "/usr/lib/python2.7/ConfigParser.py", line 370, in getboolean
raise ValueError, 'Not a boolean: %s' % v
ValueError: Not a boolean: False
ENABLE_AMQP = True
AMQP_VERBOSE = True
AMQP_HOST = 192.168.1.134
AMQP_PORT = 5671
AMQP_VHOST = /sensu
AMQP_USER = sensu
AMQP_PASSWORD = mypass
AMQP_EXCHANGE = metrics
AMQP_METRIC_NAME_IN_BODY = True
Kindly help me out. I am in need of it....
For the benefit of those coming from Google, the problem may actually be that you're missing the Python module txAMQP. You can install the module with:
pip install txamqp
or on Ubuntu (tested on Ubuntu 14.04)
sudo apt-get install python-txamqp

Categories

Resources