I am trying to create a model field for US States that can be used across multiple models in my app. I have a dictionary of common state abbreviations and spellings matched to a standardized set of names - e.g.
state_dict = {"WV": "West Virginia", "W Virginia": "West Virginia", "WY": "Wyoming"}
I'd like the model field to automatically look up its value against the dictionary and set the field's value to the standardized name if a match is found. If no match is found, the field should raise an exception of some sort.
Things I've Tried
Choice Field- This doesn't work for my use case, as the models are only modified through a REST API. Furthermore the API receives data from 3p sources, so enforcing the standardization client-side isn't an option.
Django-Localflavor US - I've tried to use the custom state field provided by this package, but it just implements a choice field that doesn't automatically standardize the data.
First of all, I'd save the canonical value in one model and the possible variations in another model in which a foreign key points to the canonical value.
During form validation (or if the data are acquired differently, then maybe in pre_save), you could look up the input value in the variations model; if found, change the value to the canonical one, if not found, raise an error.
Related
How do I edit/remove feature definitions (name/type) from my AWS Sagemaker Feature Group? From what I encounter in the Feature Store API, there are just options to delete Feature Group or record. I Tried to search the documentation for feature delete/edit methods without success. The current solution I see is to delete the Feature Group and recreate it with the correct feature definitions.
SageMaker Feature Store supports the ability to delete an entire feature record, but not a specific feature. More specifically, the current version of Feature Store supports only immutable feature groups. Once you create a feature group, its schema cannot be changed.
Just a simple question, I'm stuck at a scenario where I want to pass multiple information other than the pipeline itself inside a PMML file.
Other information like:
Average of all columns in dataset avg(col1), ... abg(coln)
P values of all features.
Correlation of all features with target.
There can be more of those, but the situation is like this as you can see. I know they can be easily sent with other file specifically made for it, but since it is regarding the ML model, I want them in the single file: PMML.
The Question is:
Can we add any additional information in PMML file that is extra in nature and might not be related with the model so that it can be used on the another side?
If that becomes possible, somehow, it would be much more helpful.
The PMML standard is extensible with custom elements. However, in the current case, all your needs appear to be served by existing PMML elements.
Average of all columns in dataset avg(col1), ... abg(coln)
P values of all features
You can store descriptive statistics about features using the ModelStats element.
Correlation of all features with target
You can store function information using the ModelExplanation element.
I wonder if there is any way I can get recommendations for a new user, using an already trained WALS model, and given the list of items the user liked.
Currently, to get a recommendation you must provide the id of the user, which must be among the users the model was trained with. I would like to get a recommendation by providing the list of items that were liked by a new user.
There is a similar feature in the implicit python library
What you are describing is called "cold start problem".
You want a recommendation from no information on user's past behaviour.
As Matrix factorization needs historical data from the user, the best recommendation you can make if a most-popular recommendation.
To tackle this problem, you can add another type of model that handle this. You can, for example, add user's data in the algorithm in order not to be absolutely dependant on past data or by doing the online recommendation by analysing data during session.
In Odoo 10 I have created my own custom application (using the new studio feature), however I have run into an issue trying to compute data between records that belong to different views.
In the scenario I have two models (model A and model B), where records from model B are connect to records from model A via a many2one relational field. There is a field in Model B that counts a numerical value entered into it.
Ideally what I would like to achieve is have some form of Automated Action / Server Action, that loops through the records in Model A, then loops through related records in Model B adding together the values of the previously mentioned numerical value field and sets the value of a field in model A equal to the equated number, before continuing onto the next record.
For example sake say the field names are:
Model A = x_a
- Model A ID Field = x_id_field
- Target field for computed value = x_compute
Model B = x_b
- many2one field = x_a_id
- numerical field = x_value_field
I have attempted to use the automated actions to execute some basic Python code (because I thought this would be as simple as a nested loop) however all my attempts have been failures due to not being familiar with how to loop through records in odoo and how to access other models and their records (from python).
How would I go about accomplishing this?
Ideally what I would like to achieve is have some form of Automated
Action / Server Action, that loops through the records in Model A,
then loops through related records in Model B adding together the
values of the previously mentioned numerical value field and sets the
value of a field in model A equal to the equated number, before
continuing onto the next record.
Create an Automated Action with Related Document Model = model a
On the Actions tab create a Server Action:
model_b_records = self.env['model_b'].search([('many2one_field', '!=', False)])
for record in model_b_records:
record.many2one_field.target_field_for_computed_value = record.numerical_field
Save the Server Action and execute it.
The code should be self-explanatory, for any questions do not hesitate to ask and comment below.
I want to create an app that stores bills for me. Since I don't have fixed prices for anything there is no need to store my services in an extra model. I just want to store data pairs of "action" and "price" to print them out nicely in a table.
Is there something in django that can help me with that task or should I just put all data pairs together in a textfield and explode it every time i want to use it ?
The number of data pairs per bill is not fixed. Data pairs are used only in one bill, so i don't want an extra table.
Instead of a plain TextField you should look at field types that are better suited for storing structured data: In addition to Acorn's suggestion (django-hstore) a JsonField or a PickleField might be suitable (and more portable) solutions for your use case.
You might be interested in Postgres's hstore: http://www.postgresql.org/docs/9.1/static/hstore.html
https://github.com/jordanm/django-hstore/