Created
November 2, 2019 08:16
-
-
Save Jeet1994/762d8429d02dc864c85d1b5d913cdff8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| { | |
| "cells": [ | |
| { | |
| "cell_type": "code", | |
| "execution_count": 97, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "import pandas as pd" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 98, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train = pd.read_csv(\"train.csv\") " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 99, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test = pd.read_csv(\"test.csv\") " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 100, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "#used for splitting dataset if not already split, \n", | |
| "from sklearn.model_selection import train_test_split\n", | |
| "#x = data.iloc[:, :-1].values\n", | |
| "#y = data.iloc[:, 1].values\n", | |
| "#x_train, x_test, y_train, y_test = train_test_split(x, y,test_size=1/3, random_state=0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 101, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Loan_ID 0\n", | |
| "Gender 13\n", | |
| "Married 3\n", | |
| "Dependents 15\n", | |
| "Education 0\n", | |
| "Self_Employed 32\n", | |
| "ApplicantIncome 0\n", | |
| "CoapplicantIncome 0\n", | |
| "LoanAmount 22\n", | |
| "Loan_Amount_Term 14\n", | |
| "Credit_History 50\n", | |
| "Property_Area 0\n", | |
| "Loan_Status 0\n", | |
| "dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 101, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "train.apply(lambda x: sum(x.isnull()),axis=0) # checking missing values in each column of train dataset" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 102, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Loan_ID 0\n", | |
| "Gender 11\n", | |
| "Married 0\n", | |
| "Dependents 10\n", | |
| "Education 0\n", | |
| "Self_Employed 23\n", | |
| "ApplicantIncome 0\n", | |
| "CoapplicantIncome 0\n", | |
| "LoanAmount 5\n", | |
| "Loan_Amount_Term 6\n", | |
| "Credit_History 29\n", | |
| "Property_Area 0\n", | |
| "dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 102, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "test.apply(lambda x: sum(x.isnull()),axis=0) #checking missing values in each column of test dataset" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 103, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Gender = train.Gender.fillna('Male')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 104, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Gender = test.Gender.fillna('Male')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 105, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Married = train.Married.fillna('Yes')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 106, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Married = test.Married.fillna('Yes')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 107, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Dependents = train.Dependents.fillna('0')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 108, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Dependents = test.Dependents.fillna('0')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 109, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Self_Employed = train.Self_Employed.fillna('No')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 110, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Self_Employed = test.Self_Employed.fillna('No')" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 111, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.LoanAmount = train.LoanAmount.fillna(train.LoanAmount.mean())" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 112, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.LoanAmount = test.LoanAmount.fillna(test.LoanAmount.mean())" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 113, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "360.0 512\n", | |
| "180.0 44\n", | |
| "480.0 15\n", | |
| "300.0 13\n", | |
| "84.0 4\n", | |
| "240.0 4\n", | |
| "120.0 3\n", | |
| "36.0 2\n", | |
| "60.0 2\n", | |
| "12.0 1\n", | |
| "Name: Loan_Amount_Term, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 113, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "train['Loan_Amount_Term'].value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 114, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Loan_Amount_Term = train.Loan_Amount_Term.fillna(360.0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 115, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "360.0 311\n", | |
| "180.0 22\n", | |
| "480.0 8\n", | |
| "300.0 7\n", | |
| "240.0 4\n", | |
| "84.0 3\n", | |
| "6.0 1\n", | |
| "120.0 1\n", | |
| "36.0 1\n", | |
| "350.0 1\n", | |
| "12.0 1\n", | |
| "60.0 1\n", | |
| "Name: Loan_Amount_Term, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 115, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "test['Loan_Amount_Term'].value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 116, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Loan_Amount_Term = test.Loan_Amount_Term.fillna(360.0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 117, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "1.0 475\n", | |
| "0.0 89\n", | |
| "Name: Credit_History, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 117, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "train['Credit_History'].value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 118, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "1.0 279\n", | |
| "0.0 59\n", | |
| "Name: Credit_History, dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 118, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "test['Credit_History'].value_counts()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 119, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train.Credit_History = train.Credit_History.fillna(1.0) " | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 120, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "test.Credit_History = test.Credit_History.fillna(1.0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 121, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Loan_ID 0\n", | |
| "Gender 0\n", | |
| "Married 0\n", | |
| "Dependents 0\n", | |
| "Education 0\n", | |
| "Self_Employed 0\n", | |
| "ApplicantIncome 0\n", | |
| "CoapplicantIncome 0\n", | |
| "LoanAmount 0\n", | |
| "Loan_Amount_Term 0\n", | |
| "Credit_History 0\n", | |
| "Property_Area 0\n", | |
| "Loan_Status 0\n", | |
| "dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 121, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "train.apply(lambda x: sum(x.isnull()),axis=0) #should be zero if all values are filled" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 122, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "Loan_ID 0\n", | |
| "Gender 0\n", | |
| "Married 0\n", | |
| "Dependents 0\n", | |
| "Education 0\n", | |
| "Self_Employed 0\n", | |
| "ApplicantIncome 0\n", | |
| "CoapplicantIncome 0\n", | |
| "LoanAmount 0\n", | |
| "Loan_Amount_Term 0\n", | |
| "Credit_History 0\n", | |
| "Property_Area 0\n", | |
| "dtype: int64" | |
| ] | |
| }, | |
| "execution_count": 122, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "test.apply(lambda x: sum(x.isnull()),axis=0)#should be zero if all values are filled" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 123, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Splitting traing data\n", | |
| "X_train = train.iloc[:, 1: 12].values\n", | |
| "y_train = train.iloc[:, 12].values" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 124, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "train, test = train_test_split(train, test_size=0.3, random_state=0)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 125, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([['Male', 'No', '0', ..., 360.0, 1.0, 'Urban'],\n", | |
| " ['Male', 'Yes', '1', ..., 360.0, 1.0, 'Rural'],\n", | |
| " ['Male', 'Yes', '0', ..., 360.0, 1.0, 'Urban'],\n", | |
| " ...,\n", | |
| " ['Male', 'Yes', '1', ..., 360.0, 1.0, 'Urban'],\n", | |
| " ['Male', 'Yes', '2', ..., 360.0, 1.0, 'Urban'],\n", | |
| " ['Female', 'No', '0', ..., 360.0, 0.0, 'Semiurban']], dtype=object)" | |
| ] | |
| }, | |
| "execution_count": 125, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X_train" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 126, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", | |
| "labelencoder_X = LabelEncoder()\n", | |
| "for i in range(0, 5):\n", | |
| " X_train[:,i] = labelencoder_X.fit_transform(X_train[:,i])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 127, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "C:\\Anaconda\\lib\\site-packages\\sklearn\\preprocessing\\_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.\n", | |
| "If you want the future behaviour and silence this warning, you can specify \"categories='auto'\".\n", | |
| "In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.\n", | |
| " warnings.warn(msg, FutureWarning)\n", | |
| "C:\\Anaconda\\lib\\site-packages\\sklearn\\preprocessing\\_encoders.py:451: DeprecationWarning: The 'categorical_features' keyword is deprecated in version 0.20 and will be removed in 0.22. You can use the ColumnTransformer instead.\n", | |
| " \"use the ColumnTransformer instead.\", DeprecationWarning)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "X_train[:,9] = labelencoder_X.fit_transform(X_train[:,9])\n", | |
| "X_train[:,10] = labelencoder_X.fit_transform(X_train[:,10])\n", | |
| "onehotencoder = OneHotEncoder(categorical_features = [7])\n", | |
| "X_train = onehotencoder.fit_transform(X_train).toarray()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 128, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "\n", | |
| "# Encoding the Dependent Variable\n", | |
| "labelencoder_y = LabelEncoder()\n", | |
| "y_train = labelencoder_y.fit_transform(y_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 129, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([[ 0., 0., 0., ..., 360., 1., 2.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 0.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 2.],\n", | |
| " ...,\n", | |
| " [ 0., 0., 0., ..., 360., 1., 2.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 2.],\n", | |
| " [ 0., 0., 0., ..., 360., 0., 1.]])" | |
| ] | |
| }, | |
| "execution_count": 129, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "\n", | |
| "X_train" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 130, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 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type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "\n", | |
| "y_train" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 131, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Splitting traing data\n", | |
| "X_test = test.iloc[:, 1: 12].values\n", | |
| "y_test = test.iloc[:, 12].values" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 132, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "<class 'pandas.core.frame.DataFrame'>\n", | |
| "Int64Index: 185 entries, 454 to 134\n", | |
| "Data columns (total 13 columns):\n", | |
| "Loan_ID 185 non-null object\n", | |
| "Gender 185 non-null object\n", | |
| "Married 185 non-null object\n", | |
| "Dependents 185 non-null object\n", | |
| "Education 185 non-null object\n", | |
| "Self_Employed 185 non-null object\n", | |
| "ApplicantIncome 185 non-null int64\n", | |
| "CoapplicantIncome 185 non-null float64\n", | |
| "LoanAmount 185 non-null float64\n", | |
| "Loan_Amount_Term 185 non-null float64\n", | |
| "Credit_History 185 non-null float64\n", | |
| "Property_Area 185 non-null object\n", | |
| "Loan_Status 185 non-null object\n", | |
| "dtypes: float64(4), int64(1), object(8)\n", | |
| "memory usage: 20.2+ KB\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "test.info()" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 133, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "C:\\Anaconda\\lib\\site-packages\\sklearn\\preprocessing\\_encoders.py:415: FutureWarning: The handling of integer data will change in version 0.22. Currently, the categories are determined based on the range [0, max(values)], while in the future they will be determined based on the unique values.\n", | |
| "If you want the future behaviour and silence this warning, you can specify \"categories='auto'\".\n", | |
| "In case you used a LabelEncoder before this OneHotEncoder to convert the categories to integers, then you can now use the OneHotEncoder directly.\n", | |
| " warnings.warn(msg, FutureWarning)\n", | |
| "C:\\Anaconda\\lib\\site-packages\\sklearn\\preprocessing\\_encoders.py:451: DeprecationWarning: The 'categorical_features' keyword is deprecated in version 0.20 and will be removed in 0.22. You can use the ColumnTransformer instead.\n", | |
| " \"use the ColumnTransformer instead.\", DeprecationWarning)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# Encoding categorical data\n", | |
| "# Encoding the Independent Variable\n", | |
| "from sklearn.preprocessing import LabelEncoder, OneHotEncoder\n", | |
| "labelencoder_X = LabelEncoder()\n", | |
| "for i in range(0, 5):\n", | |
| " X_test[:,i] = labelencoder_X.fit_transform(X_test[:,i])\n", | |
| "X_test[:,9] = labelencoder_X.fit_transform(X_test[:,9])\n", | |
| "X_test[:,10] = labelencoder_X.fit_transform(X_test[:,10])\n", | |
| "\n", | |
| "onehotencoder = OneHotEncoder(categorical_features = [7])\n", | |
| "X_test = onehotencoder.fit_transform(X_test).toarray()\n", | |
| "# Encoding the Dependent Variable\n", | |
| "labelencoder_y = LabelEncoder()\n", | |
| "y_test = labelencoder_y.fit_transform(y_test)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 134, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([[ 0., 0., 0., ..., 360., 1., 1.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 1.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 2.],\n", | |
| " ...,\n", | |
| " [ 0., 0., 1., ..., 360., 1., 1.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 0.],\n", | |
| " [ 0., 0., 0., ..., 360., 1., 1.]])" | |
| ] | |
| }, | |
| "execution_count": 134, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X_test" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 135, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,\n", | |
| " 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1,\n", | |
| " 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0,\n", | |
| " 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 0, 1])" | |
| ] | |
| }, | |
| "execution_count": 135, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "\n", | |
| "y_test" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 136, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Feature Scaling\n", | |
| "from sklearn.preprocessing import StandardScaler\n", | |
| "sc = StandardScaler()\n", | |
| "X_train = sc.fit_transform(X_train)\n", | |
| "X_test = sc.fit_transform(X_test)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 137, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(185, 112)" | |
| ] | |
| }, | |
| "execution_count": 137, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X_test.shape" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 138, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(614, 213)" | |
| ] | |
| }, | |
| "execution_count": 138, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "X_train.shape" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 139, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Applying PCA\n", | |
| "from sklearn.decomposition import PCA\n", | |
| "pca = PCA()\n", | |
| "X_train = pca.fit_transform(X_train)\n", | |
| "X_test = pca.fit_transform(X_test)\n", | |
| "explained_variance = pca.explained_variance_ratio_" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 140, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Feature Scaling\n", | |
| "from sklearn.preprocessing import StandardScaler\n", | |
| "sc = StandardScaler()\n", | |
| "X_train = sc.fit_transform(X_train)\n", | |
| "X_test = sc.fit_transform(X_test)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 141, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stderr", | |
| "output_type": "stream", | |
| "text": [ | |
| "C:\\Anaconda\\lib\\site-packages\\sklearn\\linear_model\\logistic.py:432: FutureWarning: Default solver will be changed to 'lbfgs' in 0.22. Specify a solver to silence this warning.\n", | |
| " FutureWarning)\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "# Fitting Logistic Regression to the Training set\n", | |
| "from sklearn.linear_model import LogisticRegression\n", | |
| "classifier = LogisticRegression(random_state = 0)\n", | |
| "classifier.fit(X_train, y_train)\n", | |
| "y_pred = classifier.predict(X_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 142, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "y_pred = classifier.predict(X_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 143, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,\n", | |
| " 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0,\n", | |
| " 0, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1,\n", | |
| " 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1,\n", | |
| " 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1,\n", | |
| " 1, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1,\n", | |
| " 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,\n", | |
| " 0, 1, 1, 1, 1, 1, 1,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 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0])" | |
| ] | |
| }, | |
| "execution_count": 143, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y_pred" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 144, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "# Predicting the Test set results\n", | |
| "y_pred = classifier.predict(X_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 145, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "The accuracy of Logistic Regression is: 0.8811074918566775\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "from sklearn import metrics\n", | |
| "print('The accuracy of Logistic Regression is: ', metrics.accuracy_score(y_pred, y_train))" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 146, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "KNeighborsClassifier(algorithm='auto', leaf_size=30, metric='minkowski',\n", | |
| " metric_params=None, n_jobs=None, n_neighbors=5, p=2,\n", | |
| " weights='uniform')" | |
| ] | |
| }, | |
| "execution_count": 146, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "# Fitting K-NN to the Training set\n", | |
| "from sklearn.neighbors import KNeighborsClassifier\n", | |
| "classifier = KNeighborsClassifier(n_neighbors = 5, metric = 'minkowski', p = 2)\n", | |
| "classifier.fit(X_train, y_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 147, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "y_pred1 = classifier.predict(X_train)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 148, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,\n", | |
| " 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1,\n", | |
| " 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1,\n", | |
| " 1, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1,\n", | |
| " 1, 0, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 0, 0,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,\n", | |
| " 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1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, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0])" | |
| ] | |
| }, | |
| "execution_count": 148, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y_pred1" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 149, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(614,)" | |
| ] | |
| }, | |
| "execution_count": 149, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y_pred.shape" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 150, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "(614,)" | |
| ] | |
| }, | |
| "execution_count": 150, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "y_pred1.shape" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 151, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [ | |
| "final_pred = (y_pred+y_pred1)/2" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 152, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([0.5, 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 0. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 0. , 0. , 1. , 0. , 1. , 0.5, 0.5, 0. , 1. ,\n", | |
| " 1. , 1. , 0. , 1. , 0. , 1. , 0. , 0.5, 0. , 1. , 0. , 1. , 1. ,\n", | |
| " 1. , 0.5, 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 0.5, 1. , 0. , 1. , 1. , 0. , 1. , 1. , 1. , 0.5, 0. , 0. , 0.5,\n", | |
| " 0. , 0.5, 1. , 1. , 0.5, 1. , 1. , 0.5, 0.5, 1. , 0.5, 0.5, 1. ,\n", | |
| " 0.5, 1. , 1. , 1. , 0. , 0. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. , 1. , 0.5, 0.5, 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 0. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 0. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0. , 0.5, 0. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 1. , 1. , 0. ,\n", | |
| " 1. , 1. , 1. , 0.5, 1. , 0.5, 1. , 1. , 0. , 1. , 0. , 0.5, 0. ,\n", | |
| " 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 1. , 1. , 0. , 1. , 1. , 0.5, 0.5, 1. , 1. , 0. , 1. ,\n", | |
| " 1. , 0. , 0. , 0. , 1. , 1. , 1. , 1. , 0.5, 1. , 0. , 0.5, 0.5,\n", | |
| " 1. , 1. , 1. , 1. , 0.5, 0.5, 1. , 1. , 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 0. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 0.5, 1. , 1. ,\n", | |
| " 1. , 0.5, 1. , 0. , 0.5, 1. , 1. , 0. , 1. , 0.5, 1. , 0. , 0.5,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 0. , 1. , 0.5, 0.5, 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 0.5, 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 0. , 1. , 0.5, 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 0.5, 0.5, 1. , 1. , 1. , 0. , 0. , 0.5, 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 0. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 0.5, 0. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 0. , 1. , 1. , 0.5, 0. , 0. , 1. , 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 0. , 1. , 0.5, 1. , 0. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 0. , 0.5, 0. , 1. ,\n", | |
| " 1. , 0.5, 1. , 1. , 1. , 0. , 0. , 0. , 1. , 0. , 1. , 0. , 1. ,\n", | |
| " 1. , 0. , 1. , 0.5, 1. , 0. , 1. , 0.5, 1. , 1. , 0. , 0.5, 1. ,\n", | |
| " 1. , 1. , 0. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 0.5, 1. , 1. , 1. , 1. , 0.5, 0. , 0.5, 1. , 0. , 0.5, 1. ,\n", | |
| " 1. , 1. , 0.5, 1. , 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 0.5, 1. ,\n", | |
| " 1. , 1. , 1. , 0.5, 1. , 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 0. , 0. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 0. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5,\n", | |
| " 0. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 1. ,\n", | |
| " 0. , 1. , 0. , 1. , 0. , 1. , 1. , 0. , 0.5, 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 1. , 1. , 1. , 0. , 1. , 1. , 0. , 0. , 0.5, 1. , 0.5,\n", | |
| " 1. , 1. , 1. , 1. , 0.5, 1. , 1. , 1. , 0. , 1. , 1. , 0. , 0. ,\n", | |
| " 1. , 1. , 1. , 1. , 0. , 1. , 1. , 1. , 1. , 1. , 1. , 1. , 0.5,\n", | |
| " 1. , 1. , 0. , 1. , 1. , 1. , 1. , 0.5, 0.5, 1. , 1. , 1. , 1. ,\n", | |
| " 1. , 1. , 0. ])" | |
| ] | |
| }, | |
| "execution_count": 152, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "final_pred" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 153, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "name": "stdout", | |
| "output_type": "stream", | |
| "text": [ | |
| "[[0 1 1 1 1 1 1 0 1 0 1 1 1 1 1 1 1 0 0 1 0 1 0 0 0 1 1 1 0 1 0 1 0 0 0 1\n", | |
| " 0 1 1 1 0 1 1 1 1 1 1 1 0 1 1 1 0 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1 0 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 1\n", | |
| " 1 0 1 1 1 1 0 1 0 1 0 1 1 0 0 1 1 1 1 1 1 1 1 1 0 1 1 0 0 0 1 0 1 1 1 1\n", | |
| " 0 1 1 1 0 1 1 0 0 1 1 1 1 0 1 1 1 1 1 1 1 0 1 1 0 1 1 1 1 0 0 1 1 1 1 1\n", | |
| " 1 0]]\n" | |
| ] | |
| } | |
| ], | |
| "source": [ | |
| "mode = print(m[0])" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": 154, | |
| "metadata": {}, | |
| "outputs": [ | |
| { | |
| "data": { | |
| "text/plain": [ | |
| "array([0, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1,\n", | |
| " 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 0, 0, 0, 1, 0, 1, 1, 1, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0, 0,\n", | |
| " 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0, 1,\n", | |
| " 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 1,\n", | |
| " 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 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1, 1, 0, 1, 1,\n", | |
| " 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 1,\n", | |
| " 0, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0,\n", | |
| " 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1,\n", | |
| " 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 0],\n", | |
| " dtype=int64)" | |
| ] | |
| }, | |
| "execution_count": 154, | |
| "metadata": {}, | |
| "output_type": "execute_result" | |
| } | |
| ], | |
| "source": [ | |
| "np.apply_along_axis(lambda x: np.bincount(x).argmax(), axis=0, arr=a)" | |
| ] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| }, | |
| { | |
| "cell_type": "code", | |
| "execution_count": null, | |
| "metadata": {}, | |
| "outputs": [], | |
| "source": [] | |
| } | |
| ], | |
| "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.4" | |
| } | |
| }, | |
| "nbformat": 4, | |
| "nbformat_minor": 2 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment