Tue Aug 21, 2018 11:55 pm
Login Register Lost Password? Contact Us


First ML Program - Stuck with an Error

Topics related to the set of Machine Learning libraries and Matrix processing algorithms

Wed Mar 25, 2015 5:51 pm Change Time Zone

Hi,
I am trying to write my first ML program with the below BWR file. I am getting the below error. Can you please help?

Error: Unknown identifier before "." (expected :=) (25, 3), 2167, C:\Users\Public\Documents\HPCC Systems\ECL\My Files\MachineLearning\BWR_TestML.ecl
Error: Unknown identifier before "." (expected :=) (26, 3), 2167, C:\Users\Public\Documents\HPCC Systems\ECL\My Files\MachineLearning\BWR_TestML.ecl
Error: Unknown identifier "Kmeans" (28, 8), 2167, C:\Users\Public\Documents\HPCC Systems\ECL\My Files\MachineLearning\BWR_TestML.ecl
Error: Unknown identifier "X3" (32, 8), 2167, C:\Users\Public\Documents\HPCC Systems\ECL\My Files\MachineLearning\BWR_TestML.ecl


IMPORT * FROM ML;
IMPORT * FROM ML.Cluster;
IMPORT * FROM ML.Types;
//Define my record layout
MyRecordLayout := RECORD
UNSIGNED RecordId;
REAL XCoordinate;
REAL YCoordinate;
END;
//My dataset
X2 := DATASET([
{1, 1, 5},
{2, 5, 7},
{3, 8, 1},
{4, 0, 0},
{5, 9, 3},
{6, 1, 4},
{7, 9, 4}], MyRecordLayout);
//Three candidate centroids
CentroidCandidates := DATASET([
{1, 1, 5},
{2, 5, 7},
{3, 9, 4}], MyRecordLayout);
//Convert them to our internal field format
ml.ToField(X2, fX2);
ml.ToField(CentroidCandidates, fCentroidCandidates);
//Run K-Means for, at most, 10 iterations and stop if delta < 0.3 between iterations
fX3 := Kmeans(fX2, fCentroidCandidates, 10, 0.3);
//Convert the final centroids to the original layout
ml.FromField(fX3.result(), MyRecordLayout, X3);
//Display the results
OUTPUT(X3);
kps_mani
 
Posts: 24
Joined: Wed Mar 04, 2015 3:42 pm

Thu Mar 26, 2015 12:43 pm Change Time Zone

I believe it is how your ML folders are organized. This code compiles file using the folder organization attached below:

Code: Select all
IMPORT ML;
//Define my record layout
MyRecordLayout := RECORD
  UNSIGNED RecordId;
  REAL XCoordinate;
  REAL YCoordinate;
  END;
//My dataset
X2 := DATASET([{1, 1, 5},
               {2, 5, 7},
               {3, 8, 1},
               {4, 0, 0},
               {5, 9, 3},
               {6, 1, 4},
               {7, 9, 4}], MyRecordLayout);
//Three candidate centroids
CentroidCandidates := DATASET([{1, 1, 5},{2, 5, 7},{3, 9, 4}], MyRecordLayout);
//Convert them to our internal field format
ML.ToField(X2,fX2);
ml.ToField(CentroidCandidates, fCentroidCandidates);
//Run K-Means for, at most, 10 iterations and stop if delta < 0.3 between iterations
fX3 := ML.Cluster.Kmeans(fX2, fCentroidCandidates, 10, 0.3);
//Convert the final centroids to the original layout
ml.FromField(fX3.result(), MyRecordLayout, X3);
//Display the results
OUTPUT(X3);


Regards,

Bob
Attachments
MLLayout.jpg
Folder Layout of my ML libraries
(43.62 KiB) Downloaded 1169 times
bforeman
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 975
Joined: Wed Jun 29, 2011 7:13 pm

Fri Mar 27, 2015 7:57 pm Change Time Zone

I have attached the folder directory for your reference. I was trying to run the Cluster_Doc file which is available in the TESTS folder. It also threw the same error. Please look into it and let me know what needs to be done here.

Regards,
Subbu
Attachments
ML-Error.jpg
(152.43 KiB) Downloaded 1141 times
kps_mani
 
Posts: 24
Joined: Wed Mar 04, 2015 3:42 pm

Sat Mar 28, 2015 2:55 pm Change Time Zone

Hi Subbu,

Well, it's not the same error, but a similar error :-)
The call to KMeans is expecting a DATASET using the Types.NumericField format, which is defined as UNSIGNED, UNSIGNED4, REAL8. The DATASET passed has a typo I believe, and when I correct the typo (dDocumentsMatrix to ddocumentMatrix) and change the lMatrix definition to match the Types.NumericField format:

Code: Select all
lMatrix:=ML.Types.NumericField;


Then the example will compile and run correctly.

I have included the corrected code for your convenience.

Code: Select all
IMPORT ML;

lMatrix:=ML.Types.NumericField;

dDocumentMatrix:=DATASET([
{1,2.4639,7.8579},
{2,0.5573,9.4681},
{3,4.6054,8.4723},
{4,1.24,7.3835},
{5,7.8253,4.8205},
{6,3.0965,3.4085},
{7,8.8631,1.4446},
{8,5.8085,9.1887},
{9,1.3813,0.515},
{10,2.7123,9.2429},
{11,6.786,4.9368},
{12,9.0227,5.8075},
{13,8.55,0.074},
{14,1.7074,3.9685},
{15,5.7943,3.4692},
{16,8.3931,8.5849},
{17,4.7333,5.3947},
{18,1.069,3.2497},
{19,9.3669,7.7855},
{20,2.3341,8.5196},
{21,0.5004,2.2394},
{22,6.5147,1.8744},
{23,5.1284,2.0043},
{24,3.555,1.3365},
{25,1.9224,8.0774},
{26,6.6664,9.9721},
{27,2.5007,5.2815},
{28,8.7526,6.6125},
{29,0.0898,3.9292},
{30,1.2544,9.5753},
{31,1.5462,8.4605},
{32,3.723,4.1098},
{33,9.8581,8.0831},
{34,4.0208,2.7462},
{35,4.6232,1.3271},
{36,1.5694,2.168},
{37,1.8174,4.779},
{38,9.2858,3.3175},
{39,7.1321,2.2322},
{40,2.9921,3.2818},
{41,7.0561,9.2796},
{42,1.4107,2.6271},
{43,5.1149,8.3582},
{44,6.8967,7.6558},
{45,0.0982,8.2855},
{46,1.065,4.9598},
{47,0.3701,3.7443},
{48,3.1341,8.8177},
{49,3.1314,7.3348},
{50,9.6476,3.3575},
{51,6.1636,5.3563},
{52,8.9044,7.8936},
{53,9.7695,9.6457},
{54,2.3383,2.229},
{55,5.9883,9.3733},
{56,9.3741,4.4313},
{57,8.4276,2.9337},
{58,8.2181,1.0951},
{59,3.2603,6.9417},
{60,3.0235,0.8046},
{61,1.0006,9.4768},
{62,8.5635,9.2097},
{63,5.903,7.6075},
{64,4.3534,7.5549},
{65,8.2062,3.453},
{66,9.0327,8.9012},
{67,8.077,8.6283},
{68,4.7475,5.5387},
{69,2.4441,7.106},
{70,8.1469,1.1593},
{71,5.0788,5.315},
{72,5.1421,9.8605},
{73,7.7034,2.019},
{74,3.5393,2.2992},
{75,2.804,1.3503},
{76,4.7581,2.2302},
{77,2.6552,1.7776},
{78,7.4403,5.5851},
{79,2.6909,9.7426},
{80,7.2932,5.4318},
{81,5.7443,4.3915},
{82,3.3988,9.8385},
{83,2.5105,3.6425},
{84,4.3386,4.9175},
{85,6.5916,5.7468},
{86,2.7913,7.4308},
{87,9.3152,5.4451},
{88,9.3501,3.9941},
{89,1.7224,4.6733},
{90,6.6617,1.6269},
{91,3.0622,1.9185},
{92,0.6733,2.4744},
{93,1.355,1.0267},
{94,3.75,9.499},
{95,7.2441,0.5949},
{96,3.3434,4.9163},
{97,8.7538,5.3958},
{98,7.4316,2.6315},
{99,3.6239,5.3696},
{100,3.2393,3.0533}
],lMatrix);

// dDocumentMatrix := DATASET('~tmp::keren::randomTest',{UNSIGNED ID, REAL A, REAL B, REAL C, REAL D, REAL E}, Flat);

dCentroidMatrix:=DATASET([
{1,1,1,1,1,1},
{2,2,2,2,2,2},
{3,3,3,3,3,3},
{4,4,4,4,4,4}
],{UNSIGNED ID, REAL A, REAL B, REAL C, REAL D, REAL E});

//ML.ToField(dDocumentMatrix,dDocuments);
ML.ToField(dCentroidMatrix,dCentroids);

                                                         // EXAMPLES
KMeans:=ML.Cluster.KMeans(dDocumentMatrix,dCentroids,30,.3);  // Set up KMeans with a maximum of 30 iterations and .3 as a convergence threshold
KMeans.Allresults;                                       // The table that contains the results of each iteration
KMeans.Convergence;                                      // The number of iterations it took to converge
KMeans.Result(12);                                       // The results of iteration 12
KMeans.Delta(5,15);                                      // The distance every centroid travelled across each axis from iterations 5 to 15
KMeans.Delta(0);                                         // The total distance the centroids travelled on each axis
KMeans.DistanceDelta(5,15);                              // The straight-line distance travelled by each centroid from iterations 5 to 15
KMeans.DistanceDelta(0);                                 // The total straight-line distance each centroid travelled
KMeans.DistanceDelta();
bforeman
Community Advisory Board Member
Community Advisory Board Member
 
Posts: 975
Joined: Wed Jun 29, 2011 7:13 pm


Return to Machine Learning

Who is online

Users browsing this forum: No registered users and 1 guest