class attribute is not nominal! Weka - machine-learning

I have downloaded a dataset from the uci archive called mammographic mass data. I have saved the file into edexcel and then saved as a .csv file. The attribute information for the data set is:
Attribute Information:
BI-RADS assessment: 1 to 5 (ordinal)
Age: patient's age in years (integer)
Shape: mass shape: round=1 oval=2 lobular=3 irregular=4 (nominal)
Margin: mass margin: circumscribed=1 microlobulated=2 obscured=3 ill- defined=4 spiculated=5 (nominal)
Density: mass density high=1 iso=2 low=3 fat-containing=4 (ordinal)
Severity: benign=0 or malignant=1 (binominal)
I open the file in the experiment environment and try to run however I get the following error message:
13:01:56: Started
13:01:56: Class attribute is not nominal!
13:01:56: Interrupted
13:01:56: There was 1 error
I have tried changing the attribute to class in the explorer but that has not worked. Any suggestions would be great :)

What you need is a Filter, more specifically a Descritize filter, to preprocess your data.
For example, assuming ins is the instances object where your data set is stored. The following code shows how to use a filter.
Discretize filter = new Discretize();
filter.setOptions(...); // set options
filter.setInputFormat(ins);
ins = Filter.useFilter(ins, filter);

Related

Unable to save an Entry because matrix field is invalid - Craft CMS 2

I'm trying to save an Entry but Craft errors because of an invalid matrix field. The Entry includes a matrix field but I haven't changed it. I'm trying to edit another field. When I save the entry manually from the admin panel, it saves fine without any errors.
I have researched this problem online and a lot of people were recommending that I provide the matrix's ids when saving the entry. However, even then, I still get an error.
In the code below you'll see that I'm trying to save 3 fields:
Cover Image
Language
Tracks
Each of these fields required me to manually save them because they are relations. That's OK, however, as mentioned earlier, the matrix field (named tracks) errors.
Here's my code below
$criteria = craft()->elements->getCriteria(ElementType::Entry);
$criteria->section = "programmes";
$entry = $criteria->first([
"slug" => $programme["slug"]
]);
if ($entry) {
// Update Entry attributes
$entry->getContent()->coverImage = $entry->coverImage->ids();
$entry->getContent()->tracks = $entry->tracks->ids();
$entry->getContent()->language = $entry->language->ids();
// Save Entry
if (!craft()->entries->saveEntry($entry)) {
return $entry->getErrors();
}
}
The error that comes back is the following
Argument 1 passed to Craft\MatrixService::validateBlock() must be an instance of Craft\MatrixBlockModel, string given, called in craft/app/fieldtypes/MatrixFieldType.php on line 451
Including the matrices themselves and not their ids has worked.
$entry->getContent()->tracks = $entry->tracks->all();

Telegraf Processor value to fieldname

I have points from my Input like these two:
http,Location=Foo Key="Humidity",Value=68 1659704523000000000
http,Location=Foo Key="Temperature",Value=24,1 1659704523000000000
But I have to store them like these:
http,Location=Foo Humidity=68 1659704523000000000
http,Location=Foo Temperature=24,1 1659704523000000000
I saw almost all of Processor plugin docs, but I still not sure it is possible to use field value as a field name. Isn't it?
I still not sure it is possible to use field value as a field name. Isn't it?
Yep! The starlark processor will do this. The 'pivot' example is what you are after.
The following will create a new field based on the values of Key and Value and then remove the original values:
[[processors.starlark]]
source = '''
def apply(metric):
metric.fields[str(metric.fields['Key'])] = metric.fields['Value']
metric.fields.pop('Key',None)
metric.fields.pop('Value',None)
return metric
'''

Variable to change label on thingsboard

I would like to see if they can help me with the creation of a variable, where I can change the labels of the MQTT message that is sent from my IoT devices, in order to make it easier and to select the correct parameters when creating a dashboard. .
Example:
This is the message received to my server.
[{"n": "model", "d": "iot-zigbee1783"}, {"n": "Relay", "ap": true}, {"t": "gateway", "ma": "0035DDf45VAIoT215"}]
What I want is to change the label "d" for "deviceIoT" and "ap" for "door sensor" also if it is possible to change the true or false of the door sensor for open and closed.
You can do this with the help of Thingsboards rule-chain.
There is also an official tutorial for this:
https://thingsboard.io/docs/user-guide/rule-engine-2-0/tutorials/transform-incoming-telemetry/
They use the transformation-rule-node called script to convert temperatures from [°F] to [°C].
While this is not your use case, it shows you how to handle incoming telemetry before it is saved to the database.
You could do a mapping of value-keys like this:
var theCustomizedMessage = {};
theCustomizedMessage['customizedKey'] = msg['originalIncomingKey'];
return {msg: theCustomizedMessage, metadata: metadata, msgType: msgType};
Keep in mind that this might be contra-productive since you have to update the rule-node scripts, when something changes.
As an alternative option you can rename the key labels in the widget configuration. This will not help your dashboard developers. But a documentation document will do :)
I strongly recommend against the replacement of boolean values with strings ('closed', 'opened'). This is a job for the widgets (e.g. their value format functions).

Is it possible to apply [Rule Chain] after [Data Converter]?

I am currently working on a POC by using ThingsBoard PE.
Our raw data contains [Asset] [Attributes].
Data flow:
[IoT cloud] --https webhook carry raw data--> [ThingsBoard PE HTTP INTEGRATION] --uplink--> [ThingsBoard PE Data Converter]
My question is: is it possible to apply [Rule Chain] after [ThingsBoard PE Data Converter]? Therefore, the device can auto create relationship with [Asset] by the [Attribute], instead of [AssetName].
Example data after data converter process:
{
"deviceName": "ABC",
"deviceType": "temperature",
"attributes": {
"asset_id": 6 // <-- the id is used in asset attribute
},
"telemetry": {
"temperature": 39.43
}
}
Answering your two, separate questions:
is it possible to apply [Rule Chain] after [ThingsBoard PE Data Converter]?
Yes it is possible. Once your data is successfully integrated and you are receiving it, you can access it using the [Input] Rule Node (the default green one that is always there when you create a Rule) and route it to any other node you need.
Therefore, the device can auto create relationship with [Asset] by the [Attribute], instead of [AssetName].
So, you want the relationship to take your custom attribute and use that as the pattern that identifies the Asset you want to create the relationship from.
The PE edition already has the Create Relation Node. However, seems that as it is one is not able to do what you seek (has no option to specify custom Asset id).
However, two options you got are:
Create a Custom Rule Node that does what you want. For that try checking the Rule Node Development page from Thingsboard. You can use the Create Relation Node as base and work from there. This can be a longer solution than doing...
Enrich your incoming message's metadata, adding your desired attribute. The Create Relation Node allows you to use variables on your message's metadata in your Name and Type patterns, as seen from this screenshot I took from that node:
This allows us a workaround to what you want to do: Add a Script Transformation Node that adds attributes.asset_id to the metadata, for example as metadata.asset_id, so you can then use it as ${asset_id} on your Name and Type patterns.
For example, your Transform() method of such Script Transformation Node should look something like this:
function Transform(msg, metadata, msgType){
//assumming your desired id is msg.attributes.asset_id, add it to the metadata
metadata.asset_id = msg.attributes.asset_id;
//return the message, in your case to the Create Relation Node
return {msg: msg, metadata:metadata, msgType:msgType};
}
Finally, your Rule should be connected like this:
[Input] -> [Script Node] -> [Create Relation Node] -> [...whatever else you like]

Choropleth Map, Bokeh - Assigning patch colours based on property values

This is my first time trying to build a world map and using GeoJSONDataSource.
I'm trying to assign different colours to the patches, based on the country's 'continent' value in its properties.
Is it possible to do something along the following lines:
p.patches(... fill_color= colours['continent'])
Where colours is a dictionary with continent names as keys, and 'continent' is the country's continent value in the JSON data.
This is my current code:
from bokeh.plotting import figure, output_file, show
from bokeh.io import output_notebook
import numpy as np
from bokeh.models import GeoJSONDataSource
with open('data.geojson') as c:
countries = (c.read())
geo_source = GeoJSONDataSource(geojson=countries)
colours = {'Europe': 'red', 'Oceania': 'purple', 'Asia': 'blue', 'Africa': 'pink', "South America": 'green', "Antarctica": 'yellow', 'North America': 'orange', "Seven seas (open ocean)": 'red'}
p = figure(height=450, width=900, lod_threshold=1)
p.patches(xs='xs', ys='ys', fill_color='blue', source=geo_source)
p.multi_line(xs='xs', ys='ys', line_color='white', line_width=0.1, source=geo_source)
show(p)
EDIT
I have tried approaching this slightly differently by setting the fill_color attribute in patches to an array of colours like so:
a =[colours[c['properties']['continent']] for c in json.loads(countries)['features']]
When running this code in Jupyter Notebook, the following error comes up:
Javascript error adding output! Error: attempted to retrieve property
array for nonexistent field 'fill_color' See your browser Javascript
console for more details.
I did this function in order to asign to a geoJSON the data provided in another JSON.
My geoJSON has the international code for states (ISO 3166-2); my data joins on it.
for state in geo['features']:
codState = str(state['properties']['ISO_3166-2'])
if codState in data.keys():
if data.values() != 0:
state['properties']['data'] = data[codState]
dataJson = json.dumps(geo,ensure_ascii=True)
return dataJson

Resources