{"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_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import pandas as pd\nimport numpy as np\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport scipy.stats as st\nimport sklearn as sk\nimport io\nfrom math import pi\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.tree import DecisionTreeClassifier, export_text\nfrom sklearn.linear_model import LogisticRegression\nfrom sklearn.model_selection import train_test_split, StratifiedKFold, KFold, RandomizedSearchCV, GridSearchCV, cross_validate\nfrom sklearn.feature_extraction.text import CountVectorizer, TfidfTransformer, TfidfVectorizer\nfrom sklearn.naive_bayes import MultinomialNB\nfrom sklearn.pipeline import make_pipeline\nfrom sklearn.metrics import confusion_matrix, accuracy_score, recall_score, f1_score, make_scorer,classification_report\nfrom sklearn.neighbors import LocalOutlierFactor\nimport xgboost as xgb\nfrom sklearn import svm\nfrom sklearn import preprocessing\nfrom sklearn.ensemble import VotingClassifier\nimport plotly.graph_objects as go\nfrom plotly.subplots import make_subplots","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-07-13T20:20:24.980074Z","iopub.execute_input":"2022-07-13T20:20:24.981460Z","iopub.status.idle":"2022-07-13T20:20:24.996157Z","shell.execute_reply.started":"2022-07-13T20:20:24.981410Z","shell.execute_reply":"2022-07-13T20:20:24.993303Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = pd.read_csv('../input/amexreducido/reduced_data.csv')\n\ndata.drop('Unnamed: 0', axis=1, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:25.042433Z","iopub.execute_input":"2022-07-13T20:20:25.043293Z","iopub.status.idle":"2022-07-13T20:20:38.658176Z","shell.execute_reply.started":"2022-07-13T20:20:25.043247Z","shell.execute_reply":"2022-07-13T20:20:38.656891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:38.660357Z","iopub.execute_input":"2022-07-13T20:20:38.660693Z","iopub.status.idle":"2022-07-13T20:20:38.763001Z","shell.execute_reply.started":"2022-07-13T20:20:38.660664Z","shell.execute_reply":"2022-07-13T20:20:38.761675Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels = pd.read_csv(\"../input/amex-default-prediction/train_labels.csv\")\nlabels","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:38.764737Z","iopub.execute_input":"2022-07-13T20:20:38.765228Z","iopub.status.idle":"2022-07-13T20:20:39.391928Z","shell.execute_reply.started":"2022-07-13T20:20:38.765150Z","shell.execute_reply":"2022-07-13T20:20:39.391049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_analysis = pd.merge(data, labels, on='customer_ID', how='inner')","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:39.394275Z","iopub.execute_input":"2022-07-13T20:20:39.395125Z","iopub.status.idle":"2022-07-13T20:20:40.419101Z","shell.execute_reply.started":"2022-07-13T20:20:39.395084Z","shell.execute_reply":"2022-07-13T20:20:40.418012Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null=round((data_analysis.isna().sum()/data_analysis.shape[0]*100),2).sort_values(ascending=False).astype(str)+('%')\nnull=null.to_frame().rename(columns={0:'Nulos'})\nnull.head(30)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.420679Z","iopub.execute_input":"2022-07-13T20:20:40.421011Z","iopub.status.idle":"2022-07-13T20:20:40.663732Z","shell.execute_reply.started":"2022-07-13T20:20:40.420981Z","shell.execute_reply":"2022-07-13T20:20:40.662845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"null.head(23)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.664819Z","iopub.execute_input":"2022-07-13T20:20:40.665556Z","iopub.status.idle":"2022-07-13T20:20:40.676397Z","shell.execute_reply.started":"2022-07-13T20:20:40.665525Z","shell.execute_reply":"2022-07-13T20:20:40.675266Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(columns = null.head(23).index.values, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.677796Z","iopub.execute_input":"2022-07-13T20:20:40.678171Z","iopub.status.idle":"2022-07-13T20:20:40.815747Z","shell.execute_reply.started":"2022-07-13T20:20:40.678136Z","shell.execute_reply":"2022-07-13T20:20:40.814556Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.817314Z","iopub.execute_input":"2022-07-13T20:20:40.817995Z","iopub.status.idle":"2022-07-13T20:20:40.918721Z","shell.execute_reply.started":"2022-07-13T20:20:40.817955Z","shell.execute_reply":"2022-07-13T20:20:40.917581Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"eliminar = ['B_2', 'S_3', 'B_3', 'D_44', 'D_48', 'D_53', 'S_7', 'D_55', 'B_13', 'D_61', 'B_15', 'D_62', 'B_16', 'B_19', 'B_20', 'B_22', 'D_74', 'D_77', 'D_79', 'D_81', 'D_84', 'B_30', 'B_33', 'S_22', 'S_24', 'D_102', 'D_103', 'D_104', 'D_105', 'D_107', 'B_37', 'B_38', 'D_115', 'D_118', 'D_119', 'D_121', 'D_128', 'D_129', 'D_131', 'D_133', 'D_139', 'D_141', 'D_143']","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.920256Z","iopub.execute_input":"2022-07-13T20:20:40.921128Z","iopub.status.idle":"2022-07-13T20:20:40.929028Z","shell.execute_reply.started":"2022-07-13T20:20:40.921076Z","shell.execute_reply":"2022-07-13T20:20:40.928218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(columns = eliminar, inplace = True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:40.932513Z","iopub.execute_input":"2022-07-13T20:20:40.933041Z","iopub.status.idle":"2022-07-13T20:20:41.041296Z","shell.execute_reply.started":"2022-07-13T20:20:40.933008Z","shell.execute_reply":"2022-07-13T20:20:41.040324Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.042667Z","iopub.execute_input":"2022-07-13T20:20:41.043199Z","iopub.status.idle":"2022-07-13T20:20:41.147217Z","shell.execute_reply.started":"2022-07-13T20:20:41.043166Z","shell.execute_reply":"2022-07-13T20:20:41.146095Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"analisis_outliers = ['B_6', 'B_10', 'D_69', 'R_7', 'B_26', 'S_16', 'R_14', 'S_26', 'B_40']","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.148757Z","iopub.execute_input":"2022-07-13T20:20:41.149107Z","iopub.status.idle":"2022-07-13T20:20:41.154615Z","shell.execute_reply.started":"2022-07-13T20:20:41.149076Z","shell.execute_reply":"2022-07-13T20:20:41.153272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"z_cols = []\nfor col in analisis_outliers:\n    z_col = 'z_' + col\n    media = np.mean(data[col])\n    std = np.std(data[col])\n    data[z_col] = (data[col] - media) / std\n    z_cols.append(z_col)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.156331Z","iopub.execute_input":"2022-07-13T20:20:41.156920Z","iopub.status.idle":"2022-07-13T20:20:41.234158Z","shell.execute_reply.started":"2022-07-13T20:20:41.156884Z","shell.execute_reply":"2022-07-13T20:20:41.232944Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[z_cols]","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.235574Z","iopub.execute_input":"2022-07-13T20:20:41.236283Z","iopub.status.idle":"2022-07-13T20:20:41.453652Z","shell.execute_reply.started":"2022-07-13T20:20:41.236242Z","shell.execute_reply":"2022-07-13T20:20:41.452768Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_B_6']) >= 3)][['B_6', 'z_B_6']].sort_values(by='z_B_6', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.454759Z","iopub.execute_input":"2022-07-13T20:20:41.455520Z","iopub.status.idle":"2022-07-13T20:20:41.474490Z","shell.execute_reply.started":"2022-07-13T20:20:41.455486Z","shell.execute_reply":"2022-07-13T20:20:41.473229Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_B_6']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.475873Z","iopub.execute_input":"2022-07-13T20:20:41.476528Z","iopub.status.idle":"2022-07-13T20:20:41.619667Z","shell.execute_reply.started":"2022-07-13T20:20:41.476489Z","shell.execute_reply":"2022-07-13T20:20:41.618478Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_B_10']) >= 3)][['B_10', 'z_B_10']].sort_values(by='z_B_10', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.621472Z","iopub.execute_input":"2022-07-13T20:20:41.622153Z","iopub.status.idle":"2022-07-13T20:20:41.639356Z","shell.execute_reply.started":"2022-07-13T20:20:41.622115Z","shell.execute_reply":"2022-07-13T20:20:41.638284Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_B_10']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.640924Z","iopub.execute_input":"2022-07-13T20:20:41.641664Z","iopub.status.idle":"2022-07-13T20:20:41.788858Z","shell.execute_reply.started":"2022-07-13T20:20:41.641630Z","shell.execute_reply":"2022-07-13T20:20:41.787680Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_D_69']) >= 3)][['D_69', 'z_D_69']].sort_values(by='z_D_69', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.790681Z","iopub.execute_input":"2022-07-13T20:20:41.791164Z","iopub.status.idle":"2022-07-13T20:20:41.809134Z","shell.execute_reply.started":"2022-07-13T20:20:41.791117Z","shell.execute_reply":"2022-07-13T20:20:41.807938Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_D_69']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.810563Z","iopub.execute_input":"2022-07-13T20:20:41.811456Z","iopub.status.idle":"2022-07-13T20:20:41.957330Z","shell.execute_reply.started":"2022-07-13T20:20:41.811418Z","shell.execute_reply":"2022-07-13T20:20:41.956069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_R_7']) >= 3)][['R_7', 'z_R_7']].sort_values(by='z_R_7', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.959079Z","iopub.execute_input":"2022-07-13T20:20:41.959464Z","iopub.status.idle":"2022-07-13T20:20:41.979178Z","shell.execute_reply.started":"2022-07-13T20:20:41.959430Z","shell.execute_reply":"2022-07-13T20:20:41.978049Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_R_7']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:41.980634Z","iopub.execute_input":"2022-07-13T20:20:41.981075Z","iopub.status.idle":"2022-07-13T20:20:42.173491Z","shell.execute_reply.started":"2022-07-13T20:20:41.981042Z","shell.execute_reply":"2022-07-13T20:20:42.172259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_B_26']) >= 3)][['B_26', 'z_B_26']].sort_values(by='z_B_26', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.175079Z","iopub.execute_input":"2022-07-13T20:20:42.175500Z","iopub.status.idle":"2022-07-13T20:20:42.193633Z","shell.execute_reply.started":"2022-07-13T20:20:42.175469Z","shell.execute_reply":"2022-07-13T20:20:42.192775Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_B_26']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.194805Z","iopub.execute_input":"2022-07-13T20:20:42.195398Z","iopub.status.idle":"2022-07-13T20:20:42.341858Z","shell.execute_reply.started":"2022-07-13T20:20:42.195361Z","shell.execute_reply":"2022-07-13T20:20:42.340546Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[(abs(data['z_S_16']) >= 3)][['S_16', 'z_S_16']].sort_values(by='z_S_16', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.343370Z","iopub.execute_input":"2022-07-13T20:20:42.343743Z","iopub.status.idle":"2022-07-13T20:20:42.365063Z","shell.execute_reply.started":"2022-07-13T20:20:42.343710Z","shell.execute_reply":"2022-07-13T20:20:42.363969Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[(abs(data['z_S_16']) >= 3)].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.366954Z","iopub.execute_input":"2022-07-13T20:20:42.367525Z","iopub.status.idle":"2022-07-13T20:20:42.519159Z","shell.execute_reply.started":"2022-07-13T20:20:42.367489Z","shell.execute_reply":"2022-07-13T20:20:42.517527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[abs(data['z_R_14']) >= 3][['R_14', 'z_R_14']].sort_values(by='z_R_14', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.521004Z","iopub.execute_input":"2022-07-13T20:20:42.521705Z","iopub.status.idle":"2022-07-13T20:20:42.541309Z","shell.execute_reply.started":"2022-07-13T20:20:42.521666Z","shell.execute_reply":"2022-07-13T20:20:42.539794Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[abs(data['z_R_14']) >= 3].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.550003Z","iopub.execute_input":"2022-07-13T20:20:42.550422Z","iopub.status.idle":"2022-07-13T20:20:42.708551Z","shell.execute_reply.started":"2022-07-13T20:20:42.550385Z","shell.execute_reply":"2022-07-13T20:20:42.707357Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[abs(data['z_S_26']) >= 3][['S_26', 'z_S_26']].sort_values(by='z_S_26', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.710024Z","iopub.execute_input":"2022-07-13T20:20:42.710416Z","iopub.status.idle":"2022-07-13T20:20:42.732641Z","shell.execute_reply.started":"2022-07-13T20:20:42.710381Z","shell.execute_reply":"2022-07-13T20:20:42.731412Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[abs(data['z_S_26']) >= 3].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.734482Z","iopub.execute_input":"2022-07-13T20:20:42.734830Z","iopub.status.idle":"2022-07-13T20:20:42.884085Z","shell.execute_reply.started":"2022-07-13T20:20:42.734800Z","shell.execute_reply":"2022-07-13T20:20:42.882728Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data[abs(data['z_B_40']) >= 3][['B_40', 'z_B_40']].sort_values(by='z_B_40', ascending=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.885661Z","iopub.execute_input":"2022-07-13T20:20:42.886040Z","iopub.status.idle":"2022-07-13T20:20:42.906946Z","shell.execute_reply.started":"2022-07-13T20:20:42.886004Z","shell.execute_reply":"2022-07-13T20:20:42.905363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(data[abs(data['z_B_40']) >= 3].index, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:42.909175Z","iopub.execute_input":"2022-07-13T20:20:42.909680Z","iopub.status.idle":"2022-07-13T20:20:43.059012Z","shell.execute_reply.started":"2022-07-13T20:20:42.909632Z","shell.execute_reply":"2022-07-13T20:20:43.058067Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.061075Z","iopub.execute_input":"2022-07-13T20:20:43.062032Z","iopub.status.idle":"2022-07-13T20:20:43.164806Z","shell.execute_reply.started":"2022-07-13T20:20:43.061975Z","shell.execute_reply":"2022-07-13T20:20:43.163484Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data.drop(columns=z_cols, inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.166505Z","iopub.execute_input":"2022-07-13T20:20:43.167285Z","iopub.status.idle":"2022-07-13T20:20:43.270218Z","shell.execute_reply.started":"2022-07-13T20:20:43.167236Z","shell.execute_reply":"2022-07-13T20:20:43.268608Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.272208Z","iopub.execute_input":"2022-07-13T20:20:43.272738Z","iopub.status.idle":"2022-07-13T20:20:43.376598Z","shell.execute_reply.started":"2022-07-13T20:20:43.272688Z","shell.execute_reply":"2022-07-13T20:20:43.375233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data['S_2'] = pd.to_datetime(data['S_2']) \ndata['S_2Year'] = data['S_2'].dt.year\ndata['S_2Month'] = data['S_2'].dt.month\ndata['S_2Day'] = data['S_2'].dt.day","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.378466Z","iopub.execute_input":"2022-07-13T20:20:43.378811Z","iopub.status.idle":"2022-07-13T20:20:43.553950Z","shell.execute_reply.started":"2022-07-13T20:20:43.378781Z","shell.execute_reply":"2022-07-13T20:20:43.553079Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from sklearn.decomposition import PCA","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.555027Z","iopub.execute_input":"2022-07-13T20:20:43.555980Z","iopub.status.idle":"2022-07-13T20:20:43.560210Z","shell.execute_reply.started":"2022-07-13T20:20:43.555942Z","shell.execute_reply":"2022-07-13T20:20:43.559427Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = []\nnot_cols = []\nfor d in data.columns:\n    if (data[d].dtype == 'float64' or data[d].dtype == 'int64') and not (d == 'S_2Year' or d == 'S_2Month' or d == 'S_2Day'):\n        cols.append(d)\n    else:\n        not_cols.append(d)\nnot_cols","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.561483Z","iopub.execute_input":"2022-07-13T20:20:43.562248Z","iopub.status.idle":"2022-07-13T20:20:43.582591Z","shell.execute_reply.started":"2022-07-13T20:20:43.562214Z","shell.execute_reply":"2022-07-13T20:20:43.581319Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_parte_a = data[not_cols].copy()\ndata_parte_b = data[cols].copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.584593Z","iopub.execute_input":"2022-07-13T20:20:43.585364Z","iopub.status.idle":"2022-07-13T20:20:43.794348Z","shell.execute_reply.started":"2022-07-13T20:20:43.585295Z","shell.execute_reply":"2022-07-13T20:20:43.793500Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nulos = []\nfor col in data_parte_b.columns:\n    if data_parte_b[col].isna().sum() > 0:\n        print(col,\": \\t\",round((data_parte_b[col].isna().sum() / data_parte_b.shape[0]) * 100, 2), \"%\")\n        nulos.append(col)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.795989Z","iopub.execute_input":"2022-07-13T20:20:43.796697Z","iopub.status.idle":"2022-07-13T20:20:43.943726Z","shell.execute_reply.started":"2022-07-13T20:20:43.796652Z","shell.execute_reply":"2022-07-13T20:20:43.942325Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in nulos:\n    data_parte_b[col] = data_parte_b[col].fillna(data_parte_b[col].median())","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:43.944882Z","iopub.execute_input":"2022-07-13T20:20:43.945197Z","iopub.status.idle":"2022-07-13T20:20:44.402423Z","shell.execute_reply.started":"2022-07-13T20:20:43.945168Z","shell.execute_reply":"2022-07-13T20:20:44.401503Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"tipos_de_variables = \"DSPBR\"\nfor tipo in tipos_de_variables:\n    var = tipo + '_'\n    print(f\"{var}: {len(data_parte_b.filter(regex=var).columns)}\")","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:44.403771Z","iopub.execute_input":"2022-07-13T20:20:44.404647Z","iopub.status.idle":"2022-07-13T20:20:44.497855Z","shell.execute_reply.started":"2022-07-13T20:20:44.404593Z","shell.execute_reply":"2022-07-13T20:20:44.496372Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_d = data_parte_b.filter(regex=\"D_\").copy()\ndata_s = data_parte_b.filter(regex=\"S_\").copy()\ndata_b = data_parte_b.filter(regex=\"B_\").copy()\ndata_r = data_parte_b.filter(regex=\"R_\").copy()\ndata_p = data_parte_b.filter(regex=\"P_\").copy()","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:44.499048Z","iopub.execute_input":"2022-07-13T20:20:44.499988Z","iopub.status.idle":"2022-07-13T20:20:44.696642Z","shell.execute_reply.started":"2022-07-13T20:20:44.499949Z","shell.execute_reply":"2022-07-13T20:20:44.695421Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca_data = PCA()\npca_data.fit(data_d)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:44.698288Z","iopub.execute_input":"2022-07-13T20:20:44.698642Z","iopub.status.idle":"2022-07-13T20:20:45.685552Z","shell.execute_reply.started":"2022-07-13T20:20:44.698613Z","shell.execute_reply":"2022-07-13T20:20:45.684195Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var_cumu = np.cumsum(pca_data.explained_variance_ratio_) * 100","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:45.687601Z","iopub.execute_input":"2022-07-13T20:20:45.688974Z","iopub.status.idle":"2022-07-13T20:20:45.696769Z","shell.execute_reply.started":"2022-07-13T20:20:45.688914Z","shell.execute_reply":"2022-07-13T20:20:45.694933Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k = np.argmax(var_cumu > 97.5)\nprint(\"El numero minimo de componentes para explicar el 97.5% de la varianza es: \" + str(k))","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:45.698777Z","iopub.execute_input":"2022-07-13T20:20:45.700492Z","iopub.status.idle":"2022-07-13T20:20:45.708056Z","shell.execute_reply.started":"2022-07-13T20:20:45.700446Z","shell.execute_reply":"2022-07-13T20:20:45.706857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=k)\npca_transform=pca.fit_transform(data_d)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:45.709983Z","iopub.execute_input":"2022-07-13T20:20:45.710633Z","iopub.status.idle":"2022-07-13T20:20:49.333329Z","shell.execute_reply.started":"2022-07-13T20:20:45.710595Z","shell.execute_reply":"2022-07-13T20:20:49.331666Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columnas = [\"D_PCA_\" + f\"{i}\" for i in range(29)]\npca_d = pd.DataFrame(data = pca_transform, columns=columnas)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:49.334957Z","iopub.execute_input":"2022-07-13T20:20:49.335503Z","iopub.status.idle":"2022-07-13T20:20:49.342078Z","shell.execute_reply.started":"2022-07-13T20:20:49.335454Z","shell.execute_reply":"2022-07-13T20:20:49.340917Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca_data = PCA()\npca_data.fit(data_s)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:49.343592Z","iopub.execute_input":"2022-07-13T20:20:49.343942Z","iopub.status.idle":"2022-07-13T20:20:49.568842Z","shell.execute_reply.started":"2022-07-13T20:20:49.343909Z","shell.execute_reply":"2022-07-13T20:20:49.567507Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var_cumu = np.cumsum(pca_data.explained_variance_ratio_) * 100\n\nk = np.argmax(var_cumu > 97.5)\nprint(\"El numero minimo de componentes para explicar el 97.5% de la varianza es: \" + str(k))","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:49.570549Z","iopub.execute_input":"2022-07-13T20:20:49.571268Z","iopub.status.idle":"2022-07-13T20:20:49.581313Z","shell.execute_reply.started":"2022-07-13T20:20:49.571221Z","shell.execute_reply":"2022-07-13T20:20:49.579871Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=k)\npca_transform=pca.fit_transform(data_s)\n\ncolumnas = [\"S_PCA_\" + f\"{i}\" for i in range(13)]\npca_s = pd.DataFrame(data = pca_transform, columns=columnas)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:49.583078Z","iopub.execute_input":"2022-07-13T20:20:49.583818Z","iopub.status.idle":"2022-07-13T20:20:51.264435Z","shell.execute_reply.started":"2022-07-13T20:20:49.583769Z","shell.execute_reply":"2022-07-13T20:20:51.263292Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca_data = PCA()\npca_data.fit(data_b)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:51.265951Z","iopub.execute_input":"2022-07-13T20:20:51.266409Z","iopub.status.idle":"2022-07-13T20:20:51.646575Z","shell.execute_reply.started":"2022-07-13T20:20:51.266363Z","shell.execute_reply":"2022-07-13T20:20:51.645269Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var_cumu = np.cumsum(pca_data.explained_variance_ratio_) * 100\n\nk = np.argmax(var_cumu > 97.5)\nprint(\"El numero minimo de componentes para explicar el 97.5% de la varianza es: \" + str(k))","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:51.652817Z","iopub.execute_input":"2022-07-13T20:20:51.653652Z","iopub.status.idle":"2022-07-13T20:20:51.662563Z","shell.execute_reply.started":"2022-07-13T20:20:51.653592Z","shell.execute_reply":"2022-07-13T20:20:51.661235Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=k)\npca_transform=pca.fit_transform(data_b)\n\ncolumnas = [\"B_PCA_\" + f\"{i}\" for i in range(16)]\npca_b = pd.DataFrame(data = pca_transform, columns=columnas)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:51.664980Z","iopub.execute_input":"2022-07-13T20:20:51.666305Z","iopub.status.idle":"2022-07-13T20:20:54.136320Z","shell.execute_reply.started":"2022-07-13T20:20:51.666232Z","shell.execute_reply":"2022-07-13T20:20:54.135064Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca_data = PCA()\npca_data.fit(data_r)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:54.137720Z","iopub.execute_input":"2022-07-13T20:20:54.138063Z","iopub.status.idle":"2022-07-13T20:20:54.616110Z","shell.execute_reply.started":"2022-07-13T20:20:54.138032Z","shell.execute_reply":"2022-07-13T20:20:54.614877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"var_cumu = np.cumsum(pca_data.explained_variance_ratio_) * 100\n\nk = np.argmax(var_cumu > 97.5)\nprint(\"El numero minimo de componentes para explicar el 97.5% de la varianza es: \" + str(k))","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:54.618171Z","iopub.execute_input":"2022-07-13T20:20:54.618909Z","iopub.status.idle":"2022-07-13T20:20:54.630202Z","shell.execute_reply.started":"2022-07-13T20:20:54.618849Z","shell.execute_reply":"2022-07-13T20:20:54.628812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"k = 5","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:54.632617Z","iopub.execute_input":"2022-07-13T20:20:54.633404Z","iopub.status.idle":"2022-07-13T20:20:54.642296Z","shell.execute_reply.started":"2022-07-13T20:20:54.633327Z","shell.execute_reply":"2022-07-13T20:20:54.640385Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pca = PCA(n_components=k)\npca_transform=pca.fit_transform(data_r)\n\ncolumnas = [\"R_PCA_\" + f\"{i}\" for i in range(5)]\npca_r = pd.DataFrame(data = pca_transform, columns=columnas)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:54.644550Z","iopub.execute_input":"2022-07-13T20:20:54.645767Z","iopub.status.idle":"2022-07-13T20:20:56.170728Z","shell.execute_reply.started":"2022-07-13T20:20:54.645703Z","shell.execute_reply":"2022-07-13T20:20:56.169694Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"datasets = [data_parte_a, pca_d, pca_s, pca_b, pca_r, data_p]\nfor d in datasets:\n    d.reset_index(inplace=True)\nnuevo = pd.concat(datasets, axis=1)\nnuevo.drop(columns=['index'], inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:56.171796Z","iopub.execute_input":"2022-07-13T20:20:56.172140Z","iopub.status.idle":"2022-07-13T20:20:56.594136Z","shell.execute_reply.started":"2022-07-13T20:20:56.172107Z","shell.execute_reply":"2022-07-13T20:20:56.592845Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"nuevo","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:56.595678Z","iopub.execute_input":"2022-07-13T20:20:56.596052Z","iopub.status.idle":"2022-07-13T20:20:56.721842Z","shell.execute_reply.started":"2022-07-13T20:20:56.596017Z","shell.execute_reply":"2022-07-13T20:20:56.720417Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:56.723288Z","iopub.execute_input":"2022-07-13T20:20:56.724447Z","iopub.status.idle":"2022-07-13T20:20:56.823837Z","shell.execute_reply.started":"2022-07-13T20:20:56.724388Z","shell.execute_reply":"2022-07-13T20:20:56.822599Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = nuevo","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:56.825124Z","iopub.execute_input":"2022-07-13T20:20:56.825504Z","iopub.status.idle":"2022-07-13T20:20:56.833819Z","shell.execute_reply.started":"2022-07-13T20:20:56.825468Z","shell.execute_reply":"2022-07-13T20:20:56.831205Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"contador_total = 0\ncontador_variables = 0\nfor col in data.columns:\n    contador = 0\n    for elemento in data[col]:\n        contador_total += 1\n        if(isinstance(elemento, float) and elemento > 1):\n            contador += 1\n            contador_variables += 1\n    print(col,\": \",contador)\nprint(\"Porcentaje total: \", round(contador_variables/contador_total, 2), \"%\")","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:20:56.835843Z","iopub.execute_input":"2022-07-13T20:20:56.837119Z","iopub.status.idle":"2022-07-13T20:21:08.795156Z","shell.execute_reply.started":"2022-07-13T20:20:56.837076Z","shell.execute_reply":"2022-07-13T20:21:08.793946Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:08.796645Z","iopub.execute_input":"2022-07-13T20:21:08.797002Z","iopub.status.idle":"2022-07-13T20:21:08.915500Z","shell.execute_reply.started":"2022-07-13T20:21:08.796969Z","shell.execute_reply":"2022-07-13T20:21:08.914354Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = data.reindex(sorted(data.columns), axis=1)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:08.917439Z","iopub.execute_input":"2022-07-13T20:21:08.918398Z","iopub.status.idle":"2022-07-13T20:21:08.978212Z","shell.execute_reply.started":"2022-07-13T20:21:08.918348Z","shell.execute_reply":"2022-07-13T20:21:08.977318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:08.979753Z","iopub.execute_input":"2022-07-13T20:21:08.980455Z","iopub.status.idle":"2022-07-13T20:21:09.075046Z","shell.execute_reply.started":"2022-07-13T20:21:08.980418Z","shell.execute_reply":"2022-07-13T20:21:09.073921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for col in data.columns:\n    if( col != \"customer_ID\" and col != \"S_2\" and col != \"S_2Year\" and col != \"S_2Month\" and col != \"S_2Day\"):\n        for elemento in data[col]:\n            if(isinstance(elemento, float) and elemento > 1):\n                data[col]=(data[col]-data[col].min())/(data[col].max()-data[col].min())\n    \ndata","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:09.076882Z","iopub.execute_input":"2022-07-13T20:21:09.077612Z","iopub.status.idle":"2022-07-13T20:21:17.498658Z","shell.execute_reply.started":"2022-07-13T20:21:09.077562Z","shell.execute_reply":"2022-07-13T20:21:17.497463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"completo = pd.merge(data, labels, on='customer_ID', how='inner')\ncompleto","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:17.500084Z","iopub.execute_input":"2022-07-13T20:21:17.500452Z","iopub.status.idle":"2022-07-13T20:21:18.166276Z","shell.execute_reply.started":"2022-07-13T20:21:17.500418Z","shell.execute_reply":"2022-07-13T20:21:18.165110Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cant_total = completo.shape[0]\ncant_target1 = completo[completo['target'] == 1].shape[0]\ncant_target0 = completo[completo['target'] == 0].shape[0]\ncant_elim = cant_target0 - cant_target1\ncant_quedan = cant_total - cant_elim\n\nprint(f\"El dataset tiene {cant_total} registros, de los cuales \" + \\\n        f\"{cant_target1} son de target 1 y {cant_target0} son de target 0\")\nprint(f\"El dataset balanceado quedaría con {cant_quedan} registros\")","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.167981Z","iopub.execute_input":"2022-07-13T20:21:18.168301Z","iopub.status.idle":"2022-07-13T20:21:18.399975Z","shell.execute_reply.started":"2022-07-13T20:21:18.168273Z","shell.execute_reply":"2022-07-13T20:21:18.398741Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data_tar1 = completo[completo['target'] == 1].copy()\ndata_tar0 = completo[completo['target'] == 0].copy()\n\ndata_tar0 = data_tar0.sample(cant_target1, random_state = 1)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.401300Z","iopub.execute_input":"2022-07-13T20:21:18.402169Z","iopub.status.idle":"2022-07-13T20:21:18.623533Z","shell.execute_reply.started":"2022-07-13T20:21:18.402131Z","shell.execute_reply":"2022-07-13T20:21:18.622606Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"completo = pd.concat([data_tar1, data_tar0])\ncompleto","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.624603Z","iopub.execute_input":"2022-07-13T20:21:18.625470Z","iopub.status.idle":"2022-07-13T20:21:18.759690Z","shell.execute_reply.started":"2022-07-13T20:21:18.625430Z","shell.execute_reply":"2022-07-13T20:21:18.758120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cols = []\nnot_cols = []\nfor d in completo.columns:\n    if (completo[d].dtype == 'float64' or completo[d].dtype == 'int64'):\n        cols.append(d)\n    else:\n        not_cols.append(d)\nnot_cols","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.761144Z","iopub.execute_input":"2022-07-13T20:21:18.761967Z","iopub.status.idle":"2022-07-13T20:21:18.775802Z","shell.execute_reply.started":"2022-07-13T20:21:18.761924Z","shell.execute_reply":"2022-07-13T20:21:18.774495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"completo = pd.get_dummies(completo, columns=['D_64'], dummy_na=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.777662Z","iopub.execute_input":"2022-07-13T20:21:18.778329Z","iopub.status.idle":"2022-07-13T20:21:18.930590Z","shell.execute_reply.started":"2022-07-13T20:21:18.778290Z","shell.execute_reply":"2022-07-13T20:21:18.929196Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"completo = pd.get_dummies(completo, columns=['D_63'], dummy_na=True)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:18.932375Z","iopub.execute_input":"2022-07-13T20:21:18.932737Z","iopub.status.idle":"2022-07-13T20:21:19.083024Z","shell.execute_reply.started":"2022-07-13T20:21:18.932704Z","shell.execute_reply":"2022-07-13T20:21:19.081921Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install visualkeras","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:19.084740Z","iopub.execute_input":"2022-07-13T20:21:19.085130Z","iopub.status.idle":"2022-07-13T20:21:33.656746Z","shell.execute_reply.started":"2022-07-13T20:21:19.085097Z","shell.execute_reply":"2022-07-13T20:21:33.655416Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import tensorflow as tf\nfrom tensorflow import keras\nfrom keras.utils.vis_utils import plot_model\nimport visualkeras\n\nimport matplotlib.pyplot as plt\nimport pandas as pd\nimport numpy as np\n\nfrom sklearn.metrics import f1_score,  recall_score, precision_score, accuracy_score\n\nfrom sklearn.preprocessing import StandardScaler\n\nfrom sklearn.model_selection import train_test_split","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:33.658662Z","iopub.execute_input":"2022-07-13T20:21:33.659058Z","iopub.status.idle":"2022-07-13T20:21:44.958785Z","shell.execute_reply.started":"2022-07-13T20:21:33.659019Z","shell.execute_reply":"2022-07-13T20:21:44.957476Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"columnas_predictoras=completo.columns.to_list()\ncolumnas_predictoras.remove('target')\nd_in=len(columnas_predictoras)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:44.960277Z","iopub.execute_input":"2022-07-13T20:21:44.960940Z","iopub.status.idle":"2022-07-13T20:21:44.967391Z","shell.execute_reply.started":"2022-07-13T20:21:44.960905Z","shell.execute_reply":"2022-07-13T20:21:44.965806Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"x_train, x_test, y_train, y_test = train_test_split(completo.loc[:,columnas_predictoras],completo.loc[:,'target'],test_size=0.8)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:44.968812Z","iopub.execute_input":"2022-07-13T20:21:44.969308Z","iopub.status.idle":"2022-07-13T20:21:45.210296Z","shell.execute_reply.started":"2022-07-13T20:21:44.969262Z","shell.execute_reply":"2022-07-13T20:21:45.209227Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def plot_clasificador(modelo, x, y,title=\"\",detail=0.1):\n   \n    # nueva figura\n    plt.figure()\n    # gráfico con la predicción aprendida\n    x_min, x_max = x.iloc[:, 0].min() - 1, x.iloc[:, 0].max() + 1\n    y_min, y_max = x.iloc[:, 1].min() - 1, x.iloc[:, 1].max() + 1\n    xx, yy = np.meshgrid(np.arange(x_min, x_max, detail),\n                         np.arange(y_min, y_max, detail))\n\n    Z = np.c_[xx.ravel(), yy.ravel()]\n    \n    Z = modelo.predict(Z)\n    Z = Z.argmax(axis=1) \n    titulo = f\"{title}: regiones de cada clase\"\n    Z = Z.reshape(xx.shape)\n    plt.contourf(xx, yy, Z, alpha=0.3)  # ,  cmap='RdBu')\n    plt.colorbar()\n    plt.title(titulo)\n\n    # puntos con las clases\n    plt.scatter(x.iloc[:, 0], x.iloc[:, 1], c=y)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:45.211822Z","iopub.execute_input":"2022-07-13T20:21:45.212201Z","iopub.status.idle":"2022-07-13T20:21:45.223399Z","shell.execute_reply.started":"2022-07-13T20:21:45.212167Z","shell.execute_reply":"2022-07-13T20:21:45.222168Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# calcula la cantidad de clases\nclasses=int(completo.loc[:,'target'].max()+1)\n\nmodelo = keras.Sequential([\n    # input_shape solo en la primer capa\n    # Capa con 3 salidas, activación relu\n    keras.layers.Dense(3,input_shape=(d_in,), activation='relu'),\n    # Capa con 5 salidas, activación tanh\n    keras.layers.Dense(5, activation='tanh'),\n    #la ultima capa si o si tiene que tener tantas salidas como clases, y softmax \n    keras.layers.Dense(classes, activation='softmax')])\n\nmodelo.summary()","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:22:47.844995Z","iopub.execute_input":"2022-07-13T20:22:47.846094Z","iopub.status.idle":"2022-07-13T20:22:47.889034Z","shell.execute_reply.started":"2022-07-13T20:22:47.846032Z","shell.execute_reply":"2022-07-13T20:22:47.887439Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"visualkeras.layered_view(modelo,legend=True) ","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:45.382874Z","iopub.execute_input":"2022-07-13T20:21:45.383268Z","iopub.status.idle":"2022-07-13T20:21:45.409456Z","shell.execute_reply.started":"2022-07-13T20:21:45.383233Z","shell.execute_reply":"2022-07-13T20:21:45.408080Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#plot_clasificador(modelo,x_train,y_train,title=f\"Modelo inicial\",detail=0.05)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:45.422440Z","iopub.execute_input":"2022-07-13T20:21:45.423527Z","iopub.status.idle":"2022-07-13T20:21:45.428002Z","shell.execute_reply.started":"2022-07-13T20:21:45.423471Z","shell.execute_reply":"2022-07-13T20:21:45.426780Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#modelo.compile(\n#  optimizer=keras.optimizers.SGD(learning_rate=0.1), \n#  loss='sparse_categorical_crossentropy', \n#  metrics=['accuracy'], \n#)\n\n# Entrenamiento del modelo\n#history = modelo.fit(x_train,y_train,epochs=100,batch_size=8,verbose=False)","metadata":{"execution":{"iopub.status.busy":"2022-07-13T20:21:45.429585Z","iopub.execute_input":"2022-07-13T20:21:45.430496Z","iopub.status.idle":"2022-07-13T20:21:45.439955Z","shell.execute_reply.started":"2022-07-13T20:21:45.430460Z","shell.execute_reply":"2022-07-13T20:21:45.439001Z"},"trusted":true},"execution_count":null,"outputs":[]}]}