1 Use Xshape to get the number of features and the number of data points Report

1 use xshape to get the number of features and the

This preview shows page 1 - 3 out of 4 pages.

1. Use X.shape to get the number of features and the number of data points. Report both numbers, mentioning which number is which. (5 points) 2. For each feature, plot a histogram ( plt.hist ) of the data values. (5 points) 3. Compute the mean & standard deviation of the data points for each feature ( np.mean , np.std ). (5 points) 4. For each pair of features (1,2), (1,3), and (1,4), plot a scatterplot (see plt.plot or plt.scatter ) of the feature values, colored according to their target value (class). (For example, plot all data points with y = 0 as blue, y = 1 as green, and y = 2 as red.) (5 points) 1 For example, by doing a Print Preview in Chrome and printing it to a PDF. Please also remember to check the resulting PDF before submitting. Homework 1 UC Irvine 1 / 4
Image of page 1

Subscribe to view the full document.

CS 178: Machine Learning & Data Mining Fall 2019 Problem 2: k-nearest-neighbor predictions (25 points) In this problem, you will continue to use the Iris data and create a k-nearest-neighbor (kNN) classifier using the provided knnClassify python class. While completing this problem, please explore the implementation to become familiar with how it works. First, we will shuffle and split the data into training and validation subsets: 1 iris = np . genfromtxt ( "data/iris.txt" , delimiter = None ) # load the data 2 Y = iris [:,-1] 3 X = iris [:,0:-1] 4 # Note: indexing with ":" indicates all values (in this case, all rows); 5 # indexing with a value ("0", "1", "-1", etc.) extracts only that value (here, columns); 6 # indexing rows/columns with a range ("1:-1") extracts any row/column in that range. 7 8 import mltools as ml 9 # We ' ll use some data manipulation routines in the provided class code 10 # Make sure the "mltools" directory is in a directory on your Python path, e.g., 11 # export PYTHONPATH=$\$${PYTHONPATH}:/path/to/parent/dir 12 # or add it to your path inside Python: 13 # import sys 14 # sys.path.append( ' /path/to/parent/dir/ ' ); 15 16 np . random . seed (0) # set the random number seed 17 X , Y = ml . shuffleData ( X , Y ); # shuffle data randomly 18 # (This is a good idea in case your data are ordered in some systematic way.) 19 20 Xtr , Xva , Ytr , Yva = ml . splitData ( X , Y , 0.75); # split data into 75/25 train/validation Make sure to set the random number seed to 0 before calling shuffleData as in the example above (and in general, for every assignment). This ensures consistent behavior each time the code is run. Learner Objects Our learners (the parameterized functions that do the prediction) will be defined as python objects, derived from either an abstract classifier or abstract regressor class. The abstract base classes have a few useful functions, such as computing error rates or other measures of quality. More importantly, the learners will all follow a generic behavioral pattern, allowing us to train the function on one data set (i.e., set the parameters of the model to perform well on those data), and then make predictions on another data set.
Image of page 2
Image of page 3

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern

Ask Expert Tutors You can ask 0 bonus questions You can ask 0 questions (0 expire soon) You can ask 0 questions (will expire )
Answers in as fast as 15 minutes