Question: This is in JAVA. There are 2 methods need to be implemented and one helper method. Please show the required output and more if you

This is in JAVA. There are 2 methods need to be implemented and one helper method. Please show the required output and more if you can. Thank you.

Helper method:

/** * Find the number of unique Element in an array with only unique element * (PROVIDED) * @param arr arr * @return the number of unique element. */ public static int getNumOfUniqueElements(String[] arr) { int counter = 0; arr = getUnique(arr); for (String s : arr) { if (s != null) counter++; else break; } return counter; }

This is in JAVA. There are 2 methods need to be implemented

and one helper method. Please show the required output and more if

you can. Thank you. Helper method: /** * Find the number of

This question consists of three methods in total and you are asked to complete two of them: getUnique () and oneHotEncode().getNumofUniqueElements () is already complete and you may need it in 4.2. Question 4.1 getUnique (10 pts) 1/ 04.1 public static String[] getUnique (String[] arr) For a given string array that contains several categorical values, return the array with the unique categories but with the same length. The sequence of the returned unique element array is corresponding to the sequence of the first occurrence of each value. For example: "BMW"] Input : ["BMW", "BMW", "Toyota", "Toyota", "BMW", "Honda", Output: ["BMW" "Toyota", "Honda", null, null, null, null] Since I saw BMW immediately before the Toyota in the original array, the output array's BMW is Toyota's predecessor. Output array has identical length with the input array because we cannot exactly know beforehand how many unique values we have in the input array. The only thing we know is that the number of unique values cannot exceed the number of total elements in the input array (i.e. when all the elements are unique). Your code should work with any car manufacturer and model inputs, beyond the ones used in the example above. You also cannot assume there are only three unique car manufacturers and models. Basically DO NOT hardcode! // Provided Helper Method private static int getNumOfUniqueElements (String[] arr) For a given unique values array, return the number of non-null elements in the array. This is a helper method for the oneHotEncode () method with the result from getUnique () so that we understand how many unique elements are present in the input array For example Input: ["BMW", "Toyota", "Honda", null, null, null, null] Output: 3 You do not need to implement this method. This method is provided to you. Question 4.2 - oneHotEncode (18 pts) # 24.2 public static int[][] oneHotEncode (String[] arr) For a given categorical feature array, generate a feature matrix using one hot encoding. You should use the helper method to implement this method. For example: Input : ["BMW", "BMW", "Toyota", "Toyota", "BMW" "Honda" ! "BMW"] uniqueArray: ["BMW", "Toyota", "Honda", null, null, null, null] Output: [[1, 1, 0, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0]] A brief explanation of the output: Output: [[1, 1, 0, 0, 1, 0, 1], [0, 0, 1, 1, 0, 0, 0], [0, 0, 0, 0, 0, 1, 0]] -> -> -> (BMW) (Toyota) (Honda) The output sequence of the one-hot-encoded array should have the same sequence with the unique array you generated on. Congratulations! After you implement those one-hot-encoded arrays, now you can feed the matrix into one of the machine learning pipelines of your own

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!