{"cells":[{"metadata":{},"cell_type":"markdown","source":"# **Let's  try regression, why not ?**\n\n"},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"##### import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nfrom sklearn import preprocessing\nfrom sklearn import datasets\nfrom sklearn.externals import joblib\nfrom skimage.feature import hog\nfrom sklearn.svm import LinearSVC,SVC\nimport numpy as np\nfrom collections import Counter\nfrom sklearn.metrics import classification_report\nfrom sklearn.multiclass import OneVsRestClassifier\nfrom sklearn.decomposition import PCA\n","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"\n# load data from csv files\ntrain = pd.read_csv('../input/Kannada-MNIST/train.csv')\ntest_df = pd.read_csv('../input/Kannada-MNIST/test.csv')\ndig = pd.read_csv('../input/Kannada-MNIST/Dig-MNIST.csv')\n\n\ntrain_df=train.append(dig)\nprint(train_df.shape, test_df.shape, dig.shape)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"features = np.array(train_df.drop('label',axis=1), 'int16')\nlabels = np.array(train_df.label, 'int')\n# train original data","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# singular\nso not regressable without pseudoinverse"},{"metadata":{"trusted":true},"cell_type":"code","source":"b = np.dot ( np.linalg.inv( np.dot( features.T, features) )  ,  np.dot( features.T, labels ) )\n\nb","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"b = np.dot(np.linalg.pinv(features),labels)\nb","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# the training data predict\n27% corrrect, so probably the result will be very bad compared with the AI solutions"},{"metadata":{"trusted":true},"cell_type":"code","source":"predict = np.round( np.dot(  features,b ),0  ).astype('int')\nnp.mean(predict==labels)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"    predi = np.round( np.dot(  test_df.values[:,1:],b ),0  ).astype('int') \n    submission = pd.DataFrame({ 'id': test_df.id,'label': predi })\n    submission.to_csv(path_or_buf =\"MNIST_pca_svc.csv\", index=False)\n    submission","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":""},{"metadata":{},"cell_type":"markdown","source":"# indead 23%"},{"metadata":{"trusted":true},"cell_type":"markdown","source":"    pca =PCA(n_components=0.8,random_state=0,whiten=True)\n    total_pca =pca.fit_transform(train_df.drop('label',axis=1).append(test_df.drop('id',axis=1)))\n    print(total_pca.shape)\n    clf = SVC()\n    clf.fit(total_pca[:len(features)], labels)\n    print(classification_report(labels,clf.predict(total_pca[:len(features)])))"},{"metadata":{"trusted":true},"cell_type":"markdown","source":""}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}