Answered step by step
Verified Expert Solution
Question
1 Approved Answer
K-means. You are given training data (xi,yi) with continuous scalar-valued outputs yi. To train the model, you decide to: - Perform K-means on the training
K-means. You are given training data (xi,yi) with continuous scalar-valued outputs yi. To train the model, you decide to: - Perform K-means on the training data xi resulting in cluster centers k,k=1,,K. - Compute yk, the mean of the yi 's in each cluster k. Then, given a new input x you make a prediction: y=k=1Kexk2k=1Kykexk2 The number of clusters K and the scaling value >0 are fixed (they are not trained). In the questions below, you can assume you have the following functions: km = KMeans (n_cluster=nc) \# Creates a K-Means object km.fit(X) \# Fits the k-means clusters km.predict(X) \# Returns the index of the closest cluster for each row in X km.cluster_centers_ \# Returns the cluster centers (one cluster per row) (a) Suppose a test sample x is close to samples in a cluster of four points with outputs yi=4,4,5,6. The sample x is far from the other cluster centers. Approximately, what is y ? For full marks, provide an explanation. (b) Write a function to perform the training: def fit(Xtr,ytr,...) ... return ... The function should take whatever arguments are necessary and return the relevant parameters in the model. (c) Write a function to compute a vector of values yhat on new data x. defpredict(X,) ... return yhat Add whatever input arguments are needed
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started