Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your team is working on an online shopping website that has been receiving increased traffic over the last few months due to the introduction of

Your team is working on an online shopping website that has been receiving increased traffic over the last few months due to the introduction of new products and an increase in popularity. The growth in the number of visitors has resulted in the website becoming slower with each passing day. This is mainly because the algorithms used to design the initial website have a high runtime complexity, which worked well when the numbers of customers were low, but with the growth of the business, the website needs well-developed algorithms with a low runtime complexity to handle the dramatic increase in workload.

image text in transcribed

This is the code I already have

CODE:

import java.lang.Math;

public class SimilarCustomer { // rename as SimilarCustomer

/**

* This methods finds the most similar customer to the given customer using

* Euclidean distance

*

* @param customerBehaviorMatrix data from online store

* @param currentCustomerIndex current customer visiting the online store

* @return index of the most similar customer wrt given customer index

*/

public int findMostSimilarCustomer(double[][] customerBehaviorMatrix, int currentCustomerIndex) {

customerBehaviorMatrix = calculateNormalizedCustomerBehaviorMatrix(customerBehaviorMatrix);

double similarity[] = new double[customerBehaviorMatrix.length];

int min = 0;

for(int i=0;i

similarity[i] = calculateEuclideanDistance(customerBehaviorMatrix[i],customerBehaviorMatrix[currentCustomerIndex]);

// System.out.print(similarity[i]);System.out.print(" ");

if( similarity[min] > similarity[i] && i!=currentCustomerIndex || min == currentCustomerIndex)min = i;

}

return min;

}

/**

* This method gets a customer index and normalized customer behavior data then

* returns the most similar customer to given one

* @param normalizedCustomerBehaviorMatrix normalized customer behavior data

* @param currentCustomerIndex index of the customer which will be the base of search

* @return index of most similar other customer

*/

public int findMostSimilarCustomerIndex(double[][] normalizedCustomerBehaviorMatrix,

int currentCustomerIndex) {

double similarity[] = new double[normalizedCustomerBehaviorMatrix.length];

int min = 0;

for(int i=0;i

similarity[i] = calculateEuclideanDistance(normalizedCustomerBehaviorMatrix[i],normalizedCustomerBehaviorMatrix[currentCustomerIndex]);

// System.out.print(similarity[i]);System.out.print(" ");

if( similarity[min] > similarity[i] && i!=currentCustomerIndex || min == currentCustomerIndex)min = i;

}

return min;

}

/**

* This method normalizes given customer behavior matrix

* @param customerBehaviorMatrix customer Behavior data

* @return normalized customer behavior matrix

*/

public double[][] calculateNormalizedCustomerBehaviorMatrix(

double[][] customerBehaviorMatrix) {

//define a new return matrix

double normalizedCustomerBehaviorMatrix[][] = new double[customerBehaviorMatrix.length][customerBehaviorMatrix[0].length];

double minmax[][] = new double[2][customerBehaviorMatrix[0].length];

minmax= findMinMaxValuesOfEachColumn(customerBehaviorMatrix);

// for each entry normalize value and store in return matrix

for(int i=0;i

for(int j=0;j

normalizedCustomerBehaviorMatrix[i][j] = customerBehaviorMatrix[i][j]/minmax[1][j];

//Assign the normalized value

return normalizedCustomerBehaviorMatrix;

}

/**

* This method finds min and max values of the customer behavior matrix

* and stores them in a matrix

*

* @param costumerBehaviourMatrix data from online store

* @return 2 row matrix with first row showing min of each column and

* second row showing max of each

*/

public double[][] findMinMaxValuesOfEachColumn(double[][] customerBehaviorMatrix) {

//define a new return matrix

double minmax[][] = new double[2][customerBehaviorMatrix[0].length];

//assign min and max values to return matrix

//for each column find min and max

//System.out.println(customerBehaviorMatrix[0].length);

//System.out.println(customerBehaviorMatrix.length);

for(int i=0;i

int min = 0,max = 0;

for(int j=0;j

if(customerBehaviorMatrix[j][i]

else if(customerBehaviorMatrix[j][i] > customerBehaviorMatrix[max][i]) max = j;

}

minmax[0][i] = customerBehaviorMatrix[min][i];

minmax[1][i] = customerBehaviorMatrix[max][i];

}

return minmax;

}

/**

* This methods calculates Euclidean distance between two equally size vector

*

* @param vectorOne First vector

* @param vectorTwo Second Vector

* @return distance (double) between given two vectors

*/

public double calculateEuclideanDistance(double[] vectorOne, double[] vectorTwo) {

//check if vectors have same length

if(vectorOne.length != vectorTwo.length)return -1;

double distance = 0;

for(int i=0;i

return Math.sqrt(distance);

}

public static void main(String[] args) {

/*

* This main method is a stub.

* It does nothing.

* Feel free to write your own code to test your implementation.

* In this case, we have nothing actionable in here, just this comment block, so the JVM should rapidly lose interest and move on to the rest of your code.

*/

SimilarCustomer m = new SimilarCustomer();

double data[][] = { {1,2,3,4},

{4,5,6,7},

{2,3,4,5}

};

System.out.println(m.findMostSimilarCustomer(data,0));

}

}

I am having trouble with the following check parts

image text in transcribed

image text in transcribed

LOGO Search Bar Account & Cart Menu Seller/Manufacturer Details & Ratings Product Picture Product Details Other products by the Seller/Manufacturer 1. 2. 3. Product Details Products purchased by those who were also interested in this product 1. 2. 3. + The dataset needs to be normalized so that each behavior/property is measured on the same scale. Normalization for each entry can be done using the following formula: X;j min; max; min; ., Vi, j Formula for normalization where xij is the entry of the th customer with th behavior and min; and max; are the minimum and maximum values of the th behavior. Checks > Unit Test Incomplete Calculate the normalized customer behavior using a large matrix Unit Test Incomplete Calculate the normalized customer behavior using a small matrix Unit Test Incomplete Calculate the normalized customer behavior using an empty matrix Create a faster performing findMostSimiliar Customer() method. 6.25 out of 18.75 1 out of 3 checks passed. Review the results below for more details. Checks Unit Test Complete The new findMostSimilarCustomer() method outperforms the old method > Unit Test Incomplete findMostSimilarCustomer() works as expected > Unit Test Incomplete findMostSimilarCustomer Index() works as expected LOGO Search Bar Account & Cart Menu Seller/Manufacturer Details & Ratings Product Picture Product Details Other products by the Seller/Manufacturer 1. 2. 3. Product Details Products purchased by those who were also interested in this product 1. 2. 3. + The dataset needs to be normalized so that each behavior/property is measured on the same scale. Normalization for each entry can be done using the following formula: X;j min; max; min; ., Vi, j Formula for normalization where xij is the entry of the th customer with th behavior and min; and max; are the minimum and maximum values of the th behavior. Checks > Unit Test Incomplete Calculate the normalized customer behavior using a large matrix Unit Test Incomplete Calculate the normalized customer behavior using a small matrix Unit Test Incomplete Calculate the normalized customer behavior using an empty matrix Create a faster performing findMostSimiliar Customer() method. 6.25 out of 18.75 1 out of 3 checks passed. Review the results below for more details. Checks Unit Test Complete The new findMostSimilarCustomer() method outperforms the old method > Unit Test Incomplete findMostSimilarCustomer() works as expected > Unit Test Incomplete findMostSimilarCustomer Index() works as expected

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2010 Barcelona Spain September 2010 Proceedings Part 3 Lnai 6323

Authors: Jose L. Balcazar ,Francesco Bonchi ,Aristides Gionis ,Michele Sebag

2010th Edition

3642159389, 978-3642159381

More Books

Students also viewed these Databases questions

Question

=+3. How is the product/service generally perceived?

Answered: 1 week ago

Question

What does stickiest refer to in regard to social media

Answered: 1 week ago