|
From: james w. <jbu...@ya...> - 2015-05-06 23:35:10
|
Thanks Elbe. I actually used Numeric to nominal filter. But I later managed to get a fix to my problem from an earlier reply of yours. My problem was how to handle test data in the pre-computed matrix, but I later found out that you had replied to a similar question in May 2014.
Best regards,
James.
On Wednesday, May 6, 2015 11:57 PM, Eibe Frank <eibe(a)waikato.ac.nz> wrote:
You shouldn’t be getting any output in this case. Instead, you should be getting a message that the classifier can’t handle the data. I’ve just checked the code and I’m not sure why this isn’t happening. The getCapabilities() method requires nominal attributes, so numeric attributes shouldn’t work.
Anyway, here is the crucial bit of code that returns the kernel evaluation for two instances:
/**
*
* @param id1 the index of instance 1
* @param id2 the index of instance 2
* @param inst1 the instance 1 object
* @return the dot product
* @throws Exception if something goes wrong
*/
@Override
public double eval(int id1, int id2, Instance inst1) throws Exception {
if (m_KernelMatrix == null) {
throw new IllegalArgumentException(
"Kernel matrix has not been loaded successfully.");
}
int index1 = -1;
if (id1 > -1) {
index1 = (int) m_data.instance(id1).value(0);
} else {
index1 = (int) inst1.value(0);
}
int index2 = (int) m_data.instance(id2).value(0);
return m_KernelMatrix.get(index1, index2);
}
I suppose it will work with your data as well. It will just use the first element of the kernel matrix in every case, because all your doubles in (0,1) will be turned into the integer 0.
Cheers,
Eibe
> On 6/05/2015, at 11:15 pm, james wafula <jbukossia(a)yahoo.com> wrote:
>
> Thanks Eibe,
>
> I understood your example:
> kernelMatrix.matrix:
> 3 3
> 1 0.5 0.2
> 0.5 1 0.5
> 0.2 0.5 1
>
> train.arff:
> @relation docs
> @attribute identifier {row1, row2, row3}
> @attribute class {a, b, c}
> @data
> row1, a
> row2, b
> row3, c
>
> But here, we are ignoring the attributes d1, d2, d3. Assume we have the training and test sets:
>
> train.arff:
> @RELATION docs
> @ATTRIBUTE d1 NUMERIC
> @ATTRIBUTE d2 NUMERIC
> @ATTRIBUTE d3 NUMERIC
> @ATTRIBUTE class {a,b,c}
> @DATA
> 0.1,0.5,0.4,a
> 0.9,0.1,0.4,b
> 0.7,0.2,0.3,c
> test.arff:
> @RELATION docs
> @ATTRIBUTE d1 NUMERIC
> @ATTRIBUTE d2 NUMERIC
> @ATTRIBUTE d3 NUMERIC
> @ATTRIBUTE class {a,b,c}
> @DATA
> 0.6,2.2,1.4,?
> 0.2,0.8,0.3,?
> 0.1,0.1,0.2,?
>
> AND a precomputed matrix of similarities for training:
> kernelMatrix.matrix:
> 3 3
> 1 0.5 0.2
> 0.5 1 0.5
> 0.2 0.5 1
>
> How can we handle this situation? I have run this example in weka using the precomputed kernel and the arff file with all the attributes in it and it still gives back some results. Could someone explain what is happening here? Here are the results:
>
> === Run information ===
>
> Scheme: weka.classifiers.meta.FilteredClassifier -F "weka.filters.unsupervised.attribute.NumericToNominal -R first-last" -W weka.classifiers.functions.SMO -- -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PrecomputedKernelMatrixKernel -M /home/james/ML_PROJ_DIR/main/Tests/May5_Tests/smallTest/kernelMatrix.matrix"
> Relation: docs-weka.filters.unsupervised.attribute.ClassAssigner-Clast
> Instances: 3
> Attributes: 4
> d1
> d2
> d3
> class
> Test mode: evaluate on training data
>
> === Classifier model (full training set) ===
>
> FilteredClassifier using weka.classifiers.functions.SMO -C 1.0 -L 0.001 -P 1.0E-12 -N 0 -V -1 -W 1 -K "weka.classifiers.functions.supportVector.PrecomputedKernelMatrixKernel -M /home/james/ML_PROJ_DIR/main/Tests/May5_Tests/smallTest/kernelMatrix.matrix" on data filtered through weka.filters.unsupervised.attribute.NumericToNominal -R first-last
>
> Filtered Header
> @relation docs-weka.filters.unsupervised.attribute.ClassAssigner-Clast-weka.filters.unsupervised.attribute.NumericToNominal-Rfirst-last
>
> @attribute d1 {0.1,0.7,0.9}
> @attribute d2 {0.1,0.2,0.5}
> @attribute d3 {0.3,0.4}
> @attribute class {a,b,c}
>
> @data
>
>
> Classifier Model
> SMO
>
> Kernel used:
> Using kernel matrix from file with name: /home/Tests/smallTest/kernelMatrix.matrix
>
> Classifier for classes: a, b
>
> BinarySMO
>
> - 1 * <0.1 0.5 0.4 > * X]
> + 1 * <0.9 0.1 0.4 > * X]
> + 0
>
> Number of support vectors: 2
>
> Number of kernel evaluations: 0
>
> Classifier for classes: a, c
>
> BinarySMO
>
> 1 * <0.7 0.2 0.3 > * X]
> - 1 * <0.1 0.5 0.4 > * X]
> + 0
>
> Number of support vectors: 2
>
> Number of kernel evaluations: 0
>
> Classifier for classes: b, c
>
> BinarySMO
>
> 1 * <0.7 0.2 0.3 > * X]
> - 1 * <0.9 0.1 0.4 > * X]
> + 0
>
> Number of support vectors: 2
>
> Number of kernel evaluations: 0
>
>
>
> Time taken to build model: 0.02 seconds
>
> === Evaluation on training set ===
>
> Time taken to test model on training data: 0 seconds
>
> === Summary ===
>
> Correctly Classified Instances 3 100 %
> Incorrectly Classified Instances 0 0 %
> Kappa statistic 1
> Mean absolute error 0.2222
> Root mean squared error 0.2722
> Relative absolute error 50 %
> Root relative squared error 57.735 %
> Coverage of cases (0.95 level) 100 %
> Mean rel. region size (0.95 level) 66.6667 %
> Total Number of Instances 3
>
> === Detailed Accuracy By Class ===
>
> TP Rate FP Rate Precision Recall F-Measure MCC ROC Area PRC Area Class
> 1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 a
> 1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 b
> 1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000 c
> Weighted Avg. 1.000 0.000 1.000 1.000 1.000 1.000 1.000 1.000
>
> === Confusion Matrix ===
>
> a b c <-- classified as
> 1 0 0 | a = a
> 0 1 0 | b = b
> 0 0 1 | c = c
>
>
>
>
>
> On Wednesday, May 6, 2015 10:15 AM, Eibe Frank <eibe(a)waikato.ac.nz> wrote:
>
>
> I just tried my old example from here:
>
> http://weka.8497.n7.nabble.com/PrecomputedKernelMatrixKernel-tp26538p26545.html
>
> It works fine with the current snapshot of WEKA 3.7.
>
> Cheers,
> Eibe
>
> > On 1 May 2015, at 07:03, james wafula <jbukossia(a)yahoo.com> wrote:
> >
> > Hi all,
> >
> > I am very new to Weka. I have played around with using pre-computed kernel matrix and all was well until recently. Now I get the following error:
> >
> > Problem reading matrix from kernelMatrix.matrix
> >
> > What could be the problem? I have neither altered the kernel matrix nor the arff file at all.
> >
> > Best regards,
> >
> > James.
> >
> >
> >
> >
> > On Thursday, April 30, 2015 6:57 PM, jason roger <jasonroger8(a)gmail.com> wrote:
> >
> >
> > Dear Weka user,
> >
> > Anybody knows how Weka able to select "wordsToKeep" parameter of StringToWordVector filer?
> >
> > Thanks a lot.
> >
> > Jason
> >
> >
> >
> > _______________________________________________
> > Wekalist mailing list
> > Send posts to: Wekalist(a)list.waikato.ac.nz
> > List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
> >
> >
> > _______________________________________________
> > Wekalist mailing list
> > Send posts to: Wekalist(a)list.waikato.ac.nz
> > List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> > List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist(a)list.waikato.ac.nz
> List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
>
>
> _______________________________________________
> Wekalist mailing list
> Send posts to: Wekalist(a)list.waikato.ac.nz
> List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
> List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
_______________________________________________
Wekalist mailing list
Send posts to: Wekalist(a)list.waikato.ac.nz
List info and subscription status: http://list.waikato.ac.nz/mailman/listinfo/wekalist
List etiquette: http://www.cs.waikato.ac.nz/~ml/weka/mailinglist_etiquette.html
|