javadatabaseattributeswekaarff

Errors when opening arff file into weka


Whenever opening this file in weka constantly receive errors 'not recognised as an 'Arff data files' file. Reason: number expected, read Token[M], line 16. However whenever I try to rectify an error another would pop up. New to this and so would anyone know where I seem to be making the mistake. Appreciate the help.

    @RELATION abalone

    @ATTRIBUTE sex REAL
    @ATTRIBUTE length REAL
    @ATTRIBUTE diameter REAL
    @ATTRIBUTE height REAL
    @ATTRIBUTE wholeWeight REAL
    @ATTRIBUTE shuckedWeight REAL
    @ATTRIBUTE visceraWeight REAL 
    @ATTRIBUTE shellWeight REAL
    @ATTRIBUTE rings REAL
    @ATTRIBUTE class   { Male,Female,Infant }


    @DATA
    M,0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15
    M,0.35,0.265,0.09,0.2255,0.0995,0.0485,0.07,7
    F,0.53,0.42,0.135,0.677,0.2565,0.1415,0.21,9
    M,0.44,0.365,0.125,0.516,0.2155,0.114,0.155,10
    I,0.33,0.255,0.08,0.205,0.0895,0.0395,0.055,7
    I,0.425,0.3,0.095,0.3515,0.141,0.0775,0.12,8
    F,0.53,0.415,0.15,0.7775,0.237,0.1415,0.33,20
    F,0.545,0.425,0.125,0.768,0.294,0.1495,0.26,16
    M,0.475,0.37,0.125,0.5095,0.2165,0.1125,0.165,9
    F,0.55,0.44,0.15,0.8945,0.3145,0.151,0.32,19

Solution

  • You have 10 attribute lines, but only 9 attributes in your data.

    Also, in your data the codes are M, F, I but you have indicated they are Male, Female, Infant in your attribute statement.

    I'm guessing that you think you are just assigning class to sex, but the class variable in Weka is automatically the last variable. I've rearranged this for you below and verified that it will load properly.

    @relation 'abalone'
    
    @attribute length numeric
    @attribute diameter numeric
    @attribute height numeric
    @attribute wholeWeight numeric
    @attribute shuckedWeight numeric
    @attribute visceraWeight numeric
    @attribute shellWeight numeric
    @attribute rings numeric
    @attribute sex {M,F,I}
    
    @data
    0.455,0.365,0.095,0.514,0.2245,0.101,0.15,15,M
    0.35,0.265,0.09,0.2255,0.0995,0.0485,0.07,7,M
    0.44,0.365,0.125,0.516,0.2155,0.114,0.155,10,M
    0.475,0.37,0.125,0.5095,0.2165,0.1125,0.165,9,M
    0.53,0.42,0.135,0.677,0.2565,0.1415,0.21,9,F
    0.53,0.415,0.15,0.7775,0.237,0.1415,0.33,20,F
    0.545,0.425,0.125,0.768,0.294,0.1495,0.26,16,F
    0.55,0.44,0.15,0.8945,0.3145,0.151,0.32,19,F
    0.33,0.255,0.08,0.205,0.0895,0.0395,0.055,7,I
    0.425,0.3,0.095,0.3515,0.141,0.0775,0.12,8,I