Computer Vision News - June 2019
24 Computer Vision News Focus on 2-dimensional space. In our implementation, we use Sklearn library and matplotlib. We begin by importing the necessary libraries using: Next, we write a simple function that gets as input a low dimensional representation and labels and as outputs a plot of them. Below, X is the embedding and y is the target/labels of X. This function will look like this: Now we are ready to begin manipulating our data . The dataset object of Sklearn contains a few datasets that are ready to use. It contains datasets such as Boston house prices, iris dataset, diabetes dataset, and digits dataset. We use the digit dataset since it is simple (i.e. can almost be linearly separable), so we can expect t-SNE to give us good results. Moreover, we will be able to make some cool visualizations using the digits. To load the 10 classes of the data set and defining the feature and the target we use: Now, we are ready to use t-SNE and embed our feature vector X into a We Tried for You import numpy as np import matplotlib . pyplot as plt from matplotlib import offsetbox from sklearn import ( manifold , datasets , decomposition ) def plotEmbedding ( X , y ): X = ( X - np . min ( X , 0 )) / ( np . max ( X , 0 ) - np . min ( X , 0 )) plt . figure () for i in range ( X . shape [ 0 ]): plt . scatter ( X [ i , 0 ], X [ i , 1 ], color = plt . cm . Set1 ( y [ i ] / 10. ), label = str ( y [ i ])) plt . xticks ([]), plt . yticks ([]) plt . legend ([ '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9’ ]) plt . title ( "t-SNE embedding" ) plt . show () Dataset = datasets . load_digits ( n_class = 10 ) X = Dataset . data y = Dataset . target
Made with FlippingBook
RkJQdWJsaXNoZXIy NTc3NzU=