QuestionSimple KNN Code in SciKit Learn There’s a set of basic functions… Simple KNN Code in SciKit LearnThere’s a set of basic functions that you should understand:A function for loading a libSVM input fileThat will be used to load the train and test files.import sklearn.datasets as sk(X,y) = sk.load_svmlight_file(“colon_cancer_train_1.libsvm”)A function for creating the KNN classifierThis function takes the model parameters such as the number of neighbors and distance metric.import sklearn.neighbors as knknn_c = kn.KNeighborsClassifier(n_neighbors=3)A function that fits the classifier to the training set using the preset model parametersNotice that KNN does not need any fitting! It is a lazy classifier that does not actually “build” a model. So this fitting function is just something that needs to be called as per how the library is defined in SciKit,y)A function that applies the KNN model to some given data points & computes the classification accuracyacc = knn_c.score(X_test,y_test)Putting all these lines together, the code looks like this:import sklearn.datasets as skimport sklearn.neighbors as kn(X,y) = sk.load_svmlight_file(“colon_cancer_train_1.libsvm”)(X_test,y_test) = sk.load_svmlight_file(“colon_cancer_test_1.libsvm”)knn_c = kn.KNeighborsClassifier(n_neighbors=3),y)acc = knn_c.score(X_test,y_test)Experimenting with Different ParametersTwo main parameters for the KNN classifier areNumber of NeighborsThe Distance MetricIn this part you will experiment with different values for these two parameters.piece of code that experiments with:A number of neighbors n = [3,5,7,9,11]All distance metrics that can be used with continuous data.This set of metrics can be obtained using this function call:metrics = sorted(sklearn.neighbors.VALID_METRICS_SPARSE[‘brute’])if you print the array metrics, you will notice that the last metric is “precomputed”. In fact this one won’t work for this dataset. It only works when the data represents a pairwise distance matrix, which is not the case with our dataset.Make sure that your code tries out all different distance metrics except for the “precomputed” one.Notice that the set of parameters can be passed to the classifier on creating it:knn_c = kn.KNeighborsClassifier(n_neighbors=n, metric=m)QuestionsWhat is the maximum obtained accuracy on the test set? What are the parameter values (number of neighbors and distance metric) associated with this accuracy?What is the maximum obtained accuracy on the training set? What are the parameter values associated with this accuracy?Are the parameter values achieving maximum accuracy the same for the training and test sets?If no, what does this tell you about the classification performance of the KNN classifier?DATASET!1648&ithint=file%2cdocx&authkey=!AECG7ToMHEsBfpM (training set)!AgQzP0BOY9i6jHI_4JiDaHY5BHQ1?e=UTPkKa) test setComputer ScienceEngineering & TechnologyPython Programming IFT MISC

Order your essay today and save 20% with the discount code ESSAYHELP