{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import pandas as pd \nimport numpy as np\nimport matplotlib.pyplot as plt\nfrom sklearn.preprocessing import StandardScaler\nfrom scipy.linalg import eigh\nimport seaborn as sns\nfrom sklearn.manifold import TSNE","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = pd.read_csv('../input/train.csv')\ndata.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"label = data['label']\nlabel.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data = data.drop('label',axis= 1)\ndata.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"data.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"label.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"std_data = StandardScaler().fit_transform(data)\nstd_data.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"std_data.T.shape","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"std_data.shape","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"###  t-SNE implementation with perplexity = 30, iteration=1000 (Default)"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = TSNE(n_components=2,random_state=0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tsne_data = model.fit_transform(std_data)\ntsne_data = np.vstack((tsne_data.T,label)).T\ntsne_df = pd.DataFrame(data=tsne_data,columns=(\"f1\",\"f2\",\"label\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.FacetGrid(tsne_df,hue=\"label\",size=8).map(plt.scatter,'f1','f2').add_legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"> ###  t-SNE implementation with perplexity = 50, iteration=1000"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = TSNE(n_components=2,random_state=0,perplexity=50,n_iter=1000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tsne_data = model.fit_transform(std_data)\ntsne_data = np.vstack((tsne_data.T,label)).T\ntsne_df = pd.DataFrame(data=tsne_data,columns=(\"f1\",\"f2\",\"label\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.FacetGrid(tsne_df,hue=\"label\",size=8).map(plt.scatter,'f1','f2').add_legend()\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"###  t-SNE implementation with perplexity = 100, iteration=2000"},{"metadata":{"trusted":true},"cell_type":"code","source":"model = TSNE(n_components=2,random_state=0,perplexity=100,n_iter=2000)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"tsne_data = model.fit_transform(std_data)\ntsne_data = np.vstack((tsne_data.T,label)).T\ntsne_df = pd.DataFrame(data=tsne_data,columns=(\"f1\",\"f2\",\"label\"))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.FacetGrid(tsne_df,hue=\"label\",size=8).map(plt.scatter,'f1','f2').add_legend()\nplt.show()","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.7.0"}},"nbformat":4,"nbformat_minor":1}