Weka only changing numeric to nominal - weka

I have a CSV file that I am importing into Weka. All variables are importing as numeric. I need to change 3 of them to nominal. However when I place numerictonominal filter on it- all variables change. I only want to change 3.
1) Is there a way to just change a few via the filter
2) Or can you set it during the import. If so, I can't figure that out either.

I assume you are using the Weka Explorer (GUI). To apply the filter to specific attributes do the following.
Step 1: Select your filter in the preprocess tab
Step 2: Click on the box to the right of the "Choose" button (a new window opens)
Step 3: In the attributeIndices box enter your custom ranges
If you select the "More" button in the filter window you will get an explanation of the different options and the values you can supply.
In your particular case, the filter is by default applied to the first through last attributes. You should change the range to reflect your personal needs.
====Edit====
If you are using the Java API, the following code will point you in the right direction.
import weka.core.Instances;
import weka.filters.Filter;
import weka.filters.unsupervised.attribute.NumericToNominal;
public class Main {
public static void main(String[] args) throws Exception
{
//load training instances
Instances originalTrain= //...load data with numeric attributes
NumericToNominal convert= new NumericToNominal();
String[] options= new String[2];
options[0]="-R";
options[1]="1-2"; //range of variables to make numeric
convert.setOptions(options);
convert.setInputFormat(originalTrain);
Instances newData=Filter.useFilter(originalTrain, convert);
System.out.println("Before");
for(int i=0; i<2; i=i+1)
{
System.out.println("Nominal? "+originalTrain.attribute(i).isNominal());
}
System.out.println("After");
for(int i=0; i<2; i=i+1)
{
System.out.println("Nominal? "+newData.attribute(i).isNominal());
}
}
}

first open the arff file.
under filter click "choose" . under filter tree , navigate to unsupervised and search for "NumerictoNomial" .Click once and press Apply. Save the File and reload it. Note: Make sure you have checked the checkbox of your desired field that you want to change.

Click on the NumericToNominal tab and a window should show up, choose the appropriate attributeIndices which you want to change to nominal

Related

How to save the result of feature selection in Weka?

I’m trying to use InfoGainAttributeEval in Weka for feature selection, how to save the result? I try to save it but seems like my weka just save my input data, not the result of feature selection.
Welcome to SO. As far as I understand you want to get the ranked values of the attributes. To do this, right click on the "Ranker + InfoGainAttributeEval" statement in the "Result List" section. Select "Save result buffer". You can see the results in programs such as notepad. You can also import it into "Excel" and create it in the chart. I think you selected "Ranker" in the Search Method section. I think it is an image as seen in the figure below.
After selecting and running "InfoGainAttributeEval" and "Ranker" it will give you a "ranked" list (Use full training set). Right click and select "Save Reduced Data" then save. Open the file in notepad as well. Open in Weka too. Select the ones whose Rank value is 0 in Weka and delete them with "Remove". Let those with rank value be left. Now you can get the same result reduced with these features. Save in .arff format. Now you have acquired Reduced data.
If "Save Reduced Data" is not working for you, here is another approach.
Attribute selection can be accomplished in the Preprocess tab.
There is a bar near the top for Filtering the data. Click the
"Choose" button. Under Filters->Supervised->Attribute you will
find AttributeSelection. Select that.
Once it says "AttributeSelection" in the Filter bar, you can click
on the bar to pick a selection method and a search method as well as
set the parameters for those choices.
Once you have made your choices for the feature selection algorithm,
click Apply to the right of the filter bar so that the filter is
actually applied to the data. The data should now have the reduced
feature set. So all you need to do is save it by clicking on the
Save button at the top right.
This should save the reduced data set.

How to add a new record into an interactive grid using IG methods then set column's value using $s() api?

I am using Oracle Apex 18.2.
I have an interactive grid and a custom button to add a new row to the IG using,
apex.region("myRegionStaticId").widget().interactiveGrid('getActions').invoke('row-add-row'); then set a column's value using, $s("myColumnStaticId","2");. When I try it, it adds the first row without setting any columns' values and starts setting the value from the second row on. Even using selection-add-row or insert-record, there is always something with the first row. Here is a sample,
[https://apex.oracle.com][1]
ws = ESLAM_WS
user = forhelp
pwd = forhelppwd
app = TEST
page = Add Row on top of an IG.
After a lot of talking and testing, I've found that $s with setTimeout isn't very reliable. I've set up page 7 again to demonstrate.
If you click the Rowaddrow button twice in rapid succession (the second time before the first setValue returns), the second row will not be initialized. I'll show you a workaround for this below, but you'll
If you lower the setTimeout to, say, 10 ms, and try focusing in the Expiry Date column before clicking the Rowaddrow button, you'll find it doesn't work. This means that, while the setTimeout of 100 ms works now, it could break in the future if the IGs internal logic changed. Unlikely but who knows.
For the moment, I would say that $s can only be reliably used to set a column value in an IG for the active row. When the row-add-row action adds a new record, it does make it active, but that is done asynchronously via setTimeout. This is because the IG is based on the flyweight pattern and there are a number of async (setTimeout based) heuristics that are built in to handle focus and blur events to correctly enable and disable rows and cells as needed.
I've found the following to be the most reliable solution. Unfortunately, it's more complex than what you had before - but it was the only way I could wrangle it all together. Feel free to use it or not. See page 8 for an example.
Right-click the custom Rowaddrow button and select Create Dynamic Action. Set the Name of the DA to rowAddRow button clicked. The When settings will automatically be configured for the click event on the button.
Select the action for the new DA. Set Action to Execute JavaScript and enter the following JavaScript in the Code attribute.
addRowClicked = true; // Global used to distinguish custom button click
this.triggeringElement.disabled = true; // Disable button to serialize access
apex.region("KITCHEN_SHARE_DTL").widget().interactiveGrid("getActions").invoke("row-add-row");
Create a new Dynamic Action and set the Name to New row initialized. In the When section, set Event to Row Initialization [Interactive Grid], Section Type to Region, and Region to KITCHEN_SHARE_DTL.
Under Client-Side Condition, set Type to JavaScript expression and enter the following code in JavaScript Expression (which ensures the DA only fires for the click of the Rowaddrow button):
addRowClicked === true
Select the action for the new DA. Set Action to Set Value, Set Type to Static Assignment, and Value to 2. In Affected Elements, set Section Type to Column(s) and Column(s) to INGREDIENT_ID. This will replace the static assignment that was being done with $s. Ensure that Fire on Initialization is disabled.
Right-click the True branch for the DA and select Create TRUE Action. Set the Action to Set Value, Set Type to SQL Statement, and enter the following code in SQL Statement:
select MIN(EXPIRY_DATE) from stock
where ingredient_id = TO_NUMBER(:INGREDIENT_ID);
Set Items to Submit to INGREDIENT_ID and disable Escape Special Characters. In Affected Elements, set Selection Type to Column(s) and Column(s) to EXPIRY_DATE. Ensure that Fire on Initialization is disabled.
Right-click the True branch for the DA and select Create TRUE Action. Set Action to Execute JavaScript Code and enter the following JavaScript in the Code attribute.
addRowClicked = false; // Unset the global
$x('ADD').disabled = false; // Enable the button
Change the following code:
$s("INGREDIENT_ID","2");
with the following one:
setTimeout(function(){ $s("INGREDIENT_ID","2"); }, 100);
It seems that the IG needs a little time to render the new row before you are able to change any value.

How to disable edit mode of oracle apex interactive grid on double click?

I am using an interactive grid in oracle apex. When we double click the grid it goes into an edit mode. I want to get rid of this functionality because my grid is not editable this way.
if you don't want the user to be able to edit row content, change the column type under Report -> Columns -> Your column -> Type. For example try setting it to Display only so that the users cannot change the content.
I have been trying to replicate the same from a long time. Just found a workaround for this.
Create Dynamic Action on Interactive grid on event Double Click
Set Action = Execute JavaScript Code
Use following code in action
apex.region("emp").widget().interactiveGrid("getActions").set("edit", false);
Make sure to replace emp with static ID which you should provide in IG region.

QTreeView/QHeaderView resize only first column to stretch and interactive both

I have a QTreeView which has 5 columns. The requirement is to stretch only the first column but all the 5 columns should be resizable by user(i.e. they can be interactive as well) also. So I wrote the following code:
int numCols = myModel->columnCount();
for(int i=0;i<numCols;i++)
{
myQTreeView->resizeColumnToContents(i);
if(i==0)
{
myQTreeView->header()->setResizeMode(i,QHeaderView::Stretch);
}
else
{
myQTreeView->header()->setResizeMode(i,QHeaderView::Interactive);
}
}
But this does not work as expected for 1st column. Although the 1st column stretches but it is not resizable/interactive like rest of the columns. Hence I want to add stretch+interactive for the 1st column. Rest of the 4 columns might as well be interactive only.
Is this possible?
According to the documentation for QHeaderView::ResizeMode, when the mode has been set to QHeaderView::Stretch...
The size cannot be changed by the user or programmatically.
So, no, I don't think it's possible to achieve what you want using the standard APIs.
You could try setting the resize mode to QHeaderView::Custom and overriding the various mouse event handlers in the QHeaderView by either installing an event filter on the existing QHeaderView or by creating your own class inheriting from QHeaderView and installing an instance of it in your view via QTreeView::setHeader.

Ultragrid entire column selection when header is clicked

This might seem a very easy problem but I am stuck and can't find a way out of it. I am using ultragrid in my form with several columns. My issue is when I am trying to click on the column header I am expecting my entire column to be selected but it doesn't. I assumed the SelectTypeCol is the property for my column selection but it did not work either. I also tried to add each column to Selected.Columns collection like this UltraGrid1.DisplayLayout.Bands(0).Columns(i).Header.Selected = True but it didn't work for me either. I believe Selected is only available during runtime but not at the design mode.
So if there is an easier way to make this work, please let me know.
Thank you
You are looking for the property HeaderClickAction
grid.DisplayLayout.Override.HeaderClickAction = HeaderClickAction.Select
This will automatically flip the selection state of the entire column as Selected (or Delected) when you click on the header. Of course this means also that you loose the ability to automatically sort on all columns
You can programmatically set the Selection state of a column with code like this (C#)
grid.DisplayLayout.Bands[0].Columns["youColumnKey"].Header.Selected = true;
this will permit to leave the HeaderClickAction property to SortSingle or SortMulti, but you have to handle the situation using code and appropriate events
You need to have an InitializeLayout event on your grid. in this event you need to set the chekboxsynchronization to default and it should work here is sample code
private void ultraGrid1_InitializeLayout(object sender,
Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
{
e.Layout.Bands[0].Columns.Add("CheckBox");
e.Layout.Bands[0].Columns["CheckBox"].Style = ColumnStyle.CheckBox;
e.Layout.Bands[0].Columns["CheckBox"].Header.CheckBoxVisibility = HeaderCheckBoxVisibility.WhenUsingCheckEditor;
e.Layout.Bands[0].Columns["CheckBox"].Header.CheckBoxSynchronization = HeaderCheckBoxSynchronization.Default; <-- make sure it is set to default here
}