C1 W1 Assignment - Uncaught (in promise) TypeError: Cannot convert undefined or null to object

I have problem with the Course 1 / Week 1 Assignment. I am delayed with the delivery date for this assignment, I have been studyng javascript callbacks and promises trying to understand the problem, the code seems fine but when the program runs it reports errors.

The program needs to read 2 datasets, ‘wdbc-train.csv’ and ‘wdbc-test.csv’, the same code works fine with the first dataset and fail processing the second dataset. Firstable, I believe the second dataset, ‘wdbc-test.csv’ had wrong data, but it is fine. When I swith the order, processing first ‘wdbc-test.csv’ and after that ‘wdbc-train.csv’ I receive the error message processing the second dataset, always with the second dataset. Please help me to fix the problem.

The portion of code with the problem is:
const convertedTestingData =
await testingData.map(
({xs, ys}) => {
console.log(‘xs:’, xs, ‘ys:’, ys); // Check values here
return ({ xs: Object.values(xs), ys: Object.values(ys) })
}
).batch(10);

The error message:
C1_W1_Assignment.html:63 xs: undefined ys: undefined
C1_W1_Assignment.html:64 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
at Function.values ()
at C1_W1_Assignment.html:64:46
at tfjs@latest:17:942499
at tfjs@latest:17:220203
at e.value (tfjs@latest:17:220344)
at e.value (tfjs@latest:17:220100)
at X5 (tfjs@latest:17:243540)
at r.transform (tfjs@latest:17:942477)
at r. (tfjs@latest:17:931911)
at h (tfjs@latest:17:2100)

1 Like

Make sure your assignment notebook and other necessary files are in same folder and is able to read your data from the assignment notebook.

Thank you for the response.
The ‘data’ folder is in the same folder with the assignment code.
The .csv files are fine, if I switch the files, reading the ‘wdbc-train.csv’ for testingUrl, the program fails reading this file. Always the programs process correctly the first file and fails in the second file, no matter which file it is.
Also, I can display the ‘testingData’, the problem occurs in the .map process.

The code switching the file:

        const testingUrl = '/data/wdbc-train.csv';   
        const testingData = await tf.data.csv(testingUrl, {
            columnConfigs: {
                diagnosis: {islabel: true}
            }                    
        });   
        console.log('testingData=', await testingData); 
        const arrayTestingData = await testingData.toArray();
        console.log('arrayTestingData=', await arrayTestingData)           
        // Convert the testing data into arrays in the space below.
        // Note: In this case, the labels are integers, not strings.
        // Therefore, there is no need to convert string labels into
        // a one-hot encoded array of label values like we did in the
        // Iris dataset example.  
        const convertedTestingData = 
            await testingData.map(
                ({xs, ys}) => { 
                    console.log('xs:', xs, 'ys:', ys); // Check values here  
                    return ({ xs: Object.values(xs), ys: Object.values(ys) })   
                }
            ).batch(10);
        console.log('convertedTestingData=', await convertedTestingData);

        const arrayconvertedTestingData = await convertedTestingData.toArray();
        console.log('arrayconvertedTestingData=', await arrayconvertedTestingData); 

The output and error message:

Navigated to http://127.0.0.1:8087/C1_W1_Assignment.html
C1_W1_Assignment.html:17 trainingData= s {size: null, input: r, hasHeader: true, fullColumnNames: undefined, columnNamesValidated: false, …}
C1_W1_Assignment.html:19 arrayTrainingData= (114) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
C1_W1_Assignment.html:31 convertedTrainingData= i {size: null}
index-4ab31049.js:9 SyntaxError: Unexpected token ‘b’, “b6c0b0d1-9”… is not valid JSON
at JSON.parse ()
at Mi.parseValue (index-4ab31049.js:9:26389)
at Mi.get (index-4ab31049.js:9:26074)
at async aa (quill.tsx-efc8bc9b.js:2:42085)
(anonymous) @ index-4ab31049.js:9
(anonymous) @ index-4ab31049.js:9
await in (anonymous) (async)
aa @ quill.tsx-efc8bc9b.js:2
await in aa (async)
(anonymous) @ quill.tsx-efc8bc9b.js:19
Show 4 more frames
Show less
C1_W1_Assignment.html:33 arrayconvertedTrainingData= (12) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
C1_W1_Assignment.html:53 testingData= s {size: null, input: r, hasHeader: true, fullColumnNames: undefined, columnNamesValidated: false, …}
C1_W1_Assignment.html:55 arrayTestingData= (455) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, …]
C1_W1_Assignment.html:68 convertedTestingData= i {size: null}
C1_W1_Assignment.html:64 xs: undefined ys: undefined
C1_W1_Assignment.html:65 Uncaught (in promise) TypeError: Cannot convert undefined or null to object
at Function.values ()
at C1_W1_Assignment.html:65:46
at tfjs@latest:17:942499
at tfjs@latest:17:220203
at e.value (tfjs@latest:17:220344)
at e.value (tfjs@latest:17:220100)
at X5 (tfjs@latest:17:243540)
at r.transform (tfjs@latest:17:942477)
at r. (tfjs@latest:17:931911)
at h (tfjs@latest:17:2100)
(anonymous) @ C1_W1_Assignment.html:65
(anonymous) @ tfjs@latest:17
(anonymous) @ tfjs@latest:17
value @ tfjs@latest:17
value @ tfjs@latest:17
X5 @ tfjs@latest:17
(anonymous) @ tfjs@latest:17
(anonymous) @ tfjs@latest:17
h @ tfjs@latest:17
(anonymous) @ tfjs@latest:17
(anonymous) @ tfjs@latest:17
u @ tfjs@latest:17
o @ tfjs@latest:17
await in o (async)
(anonymous) @ C1_W1_Assignment.html:128

1 Like

Hello @Juan_J_Moreno

When I said all file same folder I also meant, it should be located where your environment assignment is looking for those files, per se in my case it was local c drive location where I placed my folder but if I remove the assignment book from that folder and directly place in local c drive, I was getting still the error.

Did you get what I am saying?

Thank you very much.
Yes I understand, both files are in local drive in my PC.

I have resolved the problem deleting all the code for the testing-data that looks identical to the code for training-data. Then, I made a copy of the training-data code, after that I rename the variables and the program finally works. I can’t find exactly where was the problem.

I’d submitted the assignment and passed.

Thanks.

2 Likes

I made sure the test and training files have same number of columns and do not have nulls, outliers etc.