From 4089674470ea195eade950a3c955b3acbe0df4cc Mon Sep 17 00:00:00 2001 From: Jean N'dah Kouagou Date: Wed, 12 Feb 2020 09:49:46 +0000 Subject: [PATCH] leetcode --- .../Jean_Ndah_FML_project-checkpoint.ipynb | 2579 +++++++++++++++++ ...inary_search_from_scratch-checkpoint.ipynb | 115 + LeetcodeExercises.ipynb | 285 ++ 3 files changed, 2979 insertions(+) create mode 100644 .ipynb_checkpoints/Jean_Ndah_FML_project-checkpoint.ipynb create mode 100644 .ipynb_checkpoints/My_binary_search_from_scratch-checkpoint.ipynb create mode 100644 LeetcodeExercises.ipynb diff --git a/.ipynb_checkpoints/Jean_Ndah_FML_project-checkpoint.ipynb b/.ipynb_checkpoints/Jean_Ndah_FML_project-checkpoint.ipynb new file mode 100644 index 0000000..ad52056 --- /dev/null +++ b/.ipynb_checkpoints/Jean_Ndah_FML_project-checkpoint.ipynb @@ -0,0 +1,2579 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# $~~~~~~~~~~~~~~~~~~~~\\color{black}{\\text{Jean N'dah Kouagou}}$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "### $~~~~~~~~~~~~~~~~~\\color{blue}{\\text{Foundation of Machine Learning}} $\n", + "\n", + "#### $~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\color{green}{\\underline{\\text{Project 1}}}$" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{black}{\\text{Introduction}}$\n", + "\n", + "In this project, we implement three machine learning algorithms: Naive Bayes, Softmax Logistic Regression and Gaussian Discriminant Analysis. The three algorithms are used for classificaction and are tested on the same data set for comparison. Some nice observations have been made which we summarise at the bottom of this notebook." + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#!pip3 install progress_bar" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np, pandas as pd, seaborn as sns, progress_bar as pb" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "from sklearn.preprocessing import LabelEncoder as le\n", + "from sklearn.feature_extraction.text import CountVectorizer\n", + "from sklearn.model_selection import train_test_split" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Naive Bayes" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class Naive_Bayes(object):\n", + " def __init__(self):\n", + " pass\n", + " \n", + " def Phi_ki(self, i, k):\n", + " \"\"\"This function is a method to compute the probabilities P(X^(i)=1/y=k)\"\"\"\n", + " Res1=np.sum((self.features.iloc[:, i] == 1) & (self.target==k))+1 # adding 1 for \n", + " #Laplace smoothing\n", + " Res2=np.sum(self.target==k)\n", + " Res3=self.target.nunique()# considering Res3 in the denominator still for\n", + " #Laplace smoothing\n", + " return Res1/(Res2+Res3)\n", + " \n", + " def train(self, features, target): \n", + " # Providing data for training\n", + " self.features=features\n", + " self.target=target\n", + " # Computing the probabilities P(y=k)\n", + " self.p_y_s=np.array([np.sum(self.target==j)/len(self.target) for j in \\\n", + " np.unique(self.target)])\n", + " #Here we compute the probabilities P(X^(i)=1/y=k)\n", + " phi_i_k_s=np.array([[self.Phi_ki(i, k) for k in np.unique(self.target)]\\\n", + " for i in range(self.features.shape[1])])\n", + " self.phi_i_k_s=phi_i_k_s\n", + "\n", + " def P_Xi_given_y(self, i, k, X):\n", + " \"\"\"This function computes P(X^(i)/y=k). Since X^(i)/y=k follows Bernouli distribution\n", + " phi_k^(i), we then return the following:\"\"\"\n", + " return self.phi_i_k_s[i][k]**(X[i])*(1-self.phi_i_k_s[i][k])**\\\n", + " (1-X[i])\n", + " \n", + " \n", + " def P_y_equal_k_given_X(self, k, X):\n", + " \"\"\"This function computes P(y=k/X) and will be used to predict a class\"\"\"\n", + " Res1=np.prod([self.P_Xi_given_y(i, k, X) for i in range(len(X))])\n", + " Res2=self.p_y_s[k]\n", + " return Res1*Res2\n", + " \n", + " def predict(self, X):\n", + " \"\"\"This function uses the above function for the predictions\"\"\"\n", + " predictions=[]\n", + " bar = pb.ProgressBar(\"predictions\", offset=2, total_width=100, min_value=0, \\\n", + " max_value=X.shape[0]-1)\n", + " for j in range(X.shape[0]):\n", + " bar(j)\n", + " List=[]\n", + " for k in np.unique(self.target):\n", + " List.append(self.P_y_equal_k_given_X(k, X.iloc[j, :]))\n", + " predictions.append(np.argmax(List))\n", + " return np.array(predictions)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Gaussian Discriminant Analysis" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class GDAMulticlass(object):\n", + " \n", + " def __init__(self, regularizer=0.1):\n", + " # The regularizer will allow us avoid singular matrices during the computations\n", + " self.regularizer=regularizer\n", + " \n", + " def train(self, features, target):\n", + " self.features=features\n", + " self.target=target\n", + " self.number_features=self.features.shape[1]\n", + " combined=pd.concat([features, target], axis=1)\n", + " # We compute the parameters mu_k associated with each class\n", + " self.mu_s=[combined[combined['target']==j].drop('target', axis=1).mean(axis=0)\\\n", + " for j in np.unique(self.target)]\n", + " # And here are the parameters phi_k associated with each class\n", + " self.phi_s=(1.0/len(self.target))*np.array([self.target[self.target==j].count() \\\n", + " for j in np.unique(target)])\n", + " \n", + " # Finally, we compute the matrix sigma\n", + " sigma=np.matrix(np.zeros([self.number_features, self.number_features]))\n", + " \n", + " bar = pb.ProgressBar(\"training\", offset=2, total_width=100, min_value=0,\\\n", + " max_value=self.target.shape[0]-1) # This tracks the progression of the computation\n", + " #of sigma\n", + " for i in range(self.target.shape[0]):\n", + " bar(i)\n", + " sigma += np.dot(np.matrix(self.features.iloc[i, :]-\\\n", + " self.mu_s[int(self.target.iloc[i])]).T, \\\n", + " np.matrix(self.features.iloc[i, :]-self.mu_s[int(self.target.iloc[i])]))\n", + " \n", + " self.sigma=(1.0/self.target.shape[0])*sigma\n", + " \n", + " def P_x_given_y(self, sigma, x, mu):\n", + " # The following if condition helps to avoid overflow in the computation of the \n", + " #exponential when its parameter is too large\n", + " if self.number_features>380:\n", + " #The following is to avoid singular matrices\n", + " if np.linalg.det(sigma)==0:\n", + " sigma=sigma+self.regularizer*np.eye(self.number_features)\n", + " comp1 = 1.0/(np.sqrt((2*np.pi)**380)*np.sqrt(np.linalg.det(sigma)))\n", + " comp2 = float(np.exp(np.dot(-0.5*np.dot(x-mu, np.linalg.inv(sigma)), x-mu)))\n", + " else:\n", + " comp1 = 1.0/(np.sqrt((2*np.pi)**380)*np.sqrt(np.linalg.det(sigma)))\n", + " comp2 = float(np.exp(np.dot(-0.5*np.dot(x-mu, np.linalg.inv(sigma)), x-mu)))\n", + " else:\n", + " if np.linalg.det(sigma)==0:\n", + " sigma=sigma+self.regularizer*np.eye(self.number_features)\n", + " comp1 = 1.0/(np.sqrt((2*np.pi)**self.features.shape[1])*\\\n", + " np.sqrt(np.linalg.det(sigma)))\n", + " comp2 = float(np.exp(np.dot(-0.5*np.dot(x-mu, np.linalg.inv(sigma)), x-mu)))\n", + " else:\n", + " comp1 = 1.0/(np.sqrt((2*np.pi)**self.features.shape[1])*\\\n", + " np.sqrt(np.linalg.det(sigma)))\n", + " comp2 = float(np.exp(np.dot(-0.5*np.dot(x-mu, np.linalg.inv(sigma)), x-mu)))\n", + " \n", + " return comp1*comp2\n", + " \n", + " def predict(self, X):\n", + " predictions=[]\n", + " bar = pb.ProgressBar(\"predictions\", offset=2, total_width=100, min_value=0, \\\n", + " max_value=X.shape[0]-1)\n", + " for i in range(X.shape[0]):\n", + " bar(i)\n", + " Prob=[self.P_x_given_y(self.sigma, X.iloc[i, :], self.mu_s[j])*self.phi_s[j]\\\n", + " for j in np.unique(self.target)]\n", + " \n", + " predictions.append(np.argmax(Prob))\n", + " \n", + " return np.array(predictions)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Multiclass Logistic Regression" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [], + "source": [ + "class MulticlassLogReg(object):\n", + " def __init__(self, lr=0.2, Max_iter=30):\n", + " self.lr=lr\n", + " self.Max_iter=Max_iter\n", + " \n", + " #Definition of the softmax function\n", + " def softmax(self, k, X):\n", + " return np.exp(X[k])/np.sum([np.exp(X[j]) for j in range(len(X))])\n", + " \n", + " #Function to compute the probability of (y=k/X_i; weights)\n", + " def prob_yequal_k_given_Xi_weights(self, X_i, k, Weights):\n", + " return self.softmax(k, [np.dot(Weights[l], X_i) for l in range(len(Weights))])\n", + " \n", + " # Function to compute the gradient associated to the target k\n", + " def get_gradient(self, k, Weights, X, y):\n", + " grad_k=-np.array([((y.iloc[i]==k)-self.prob_yequal_k_given_Xi_weights(X.iloc[i, :], k, Weights))\\\n", + " *X.iloc[i, :] for i in range(X.shape[0])]).mean(axis=0)\n", + " return grad_k\n", + " \n", + " def fit(self, features, target, weights):\n", + " self.target=target\n", + " self.weights=weights\n", + " Intercept=np.ones_like(self.target).reshape(-1,1)\n", + " features=pd.DataFrame(np.concatenate([Intercept, features], axis=1))\n", + " \n", + " num_iter=0\n", + " #To track the progress of the training process\n", + " bar=pb.ProgressBar(\"training\", offset=2, total_width=100,\\\n", + " min_value=0, max_value=self.Max_iter-1)\n", + " \n", + " while (num_iter\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
Unnamed: 0urlDrugNameratingeffectivenesssideEffectsconditionbenefitsReviewsideEffectsReviewcommentsReview
02202enalapril4Highly EffectiveMild Side Effectsmanagement of congestive heart failureslowed the progression of left ventricular dys...cough, hypotension , proteinuria, impotence , ...monitor blood pressure , weight and asses for ...
13117ortho-tri-cyclen1Highly EffectiveSevere Side Effectsbirth preventionAlthough this type of birth control has more c...Heavy Cycle, Cramps, Hot Flashes, Fatigue, Lon...I Hate This Birth Control, I Would Not Suggest...
21146ponstel10Highly EffectiveNo Side Effectsmenstrual crampsI was used to having cramps so badly that they...Heavier bleeding and clotting than normal.I took 2 pills at the onset of my menstrual cr...
\n", + "" + ], + "text/plain": [ + " Unnamed: 0 urlDrugName rating effectiveness \\\n", + "0 2202 enalapril 4 Highly Effective \n", + "1 3117 ortho-tri-cyclen 1 Highly Effective \n", + "2 1146 ponstel 10 Highly Effective \n", + "\n", + " sideEffects condition \\\n", + "0 Mild Side Effects management of congestive heart failure \n", + "1 Severe Side Effects birth prevention \n", + "2 No Side Effects menstrual cramps \n", + "\n", + " benefitsReview \\\n", + "0 slowed the progression of left ventricular dys... \n", + "1 Although this type of birth control has more c... \n", + "2 I was used to having cramps so badly that they... \n", + "\n", + " sideEffectsReview \\\n", + "0 cough, hypotension , proteinuria, impotence , ... \n", + "1 Heavy Cycle, Cramps, Hot Flashes, Fatigue, Lon... \n", + "2 Heavier bleeding and clotting than normal. \n", + "\n", + " commentsReview \n", + "0 monitor blood pressure , weight and asses for ... \n", + "1 I Hate This Birth Control, I Would Not Suggest... \n", + "2 I took 2 pills at the onset of my menstrual cr... " + ] + }, + "execution_count": 9, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Totaldata.head(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "" + ] + }, + "execution_count": 10, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAX0AAAEKCAYAAAD+XoUoAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAAIABJREFUeJzt3Xl8VfWd//HXJzcLWYGEsIWEBAiyKmAElLq0blhbsYu/unXsdHFsdexMnZnqrx07dX7tr8vM/Kad2lZqbae2lFrrtNTBolYd3ECCCLJKCJCELYEkJCFkvZ/fH7na2xjIzXqT3Pfz8eDhPed+vzefI+Gdk+/5nu8xd0dERGJDXLQLEBGRwaPQFxGJIQp9EZEYotAXEYkhCn0RkRii0BcRiSEKfRGRGKLQFxGJIQp9EZEYEh/tAjobN26c5+fnR7sMEZFhZfPmzcfdPbu7dhGFvpktB74DBICH3f0bZ2j3UeDXwAXuXhzadx/wKaAduNvd153ta+Xn51NcXBxJWSIiEmJmByNp123om1kAeBC4EqgANpnZGnff2aldOnA3sDFs3xzgRmAuMBl41sxmunt7pAciIiL9J5Ix/cVAibuXunsLsBpY0UW7fwa+BTSF7VsBrHb3ZnffD5SEPk9ERKIgktDPAcrDtitC+95hZguBXHd/sqd9RURk8EQS+tbFvnfWYzazOOD/Aff0tG/YZ9xuZsVmVlxVVRVBSSIi0huRhH4FkBu2PQU4HLadDswDXjCzA8BSYI2ZFUXQFwB3X+nuRe5elJ3d7cVnERHppUhCfxNQaGYFZpZIx4XZNW+/6e4n3X2cu+e7ez6wAbguNHtnDXCjmSWZWQFQCLzW70chIiIR6Xb2jru3mdldwDo6pmw+4u47zOwBo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XGQjXmtl9dPz7Ogh8IrrliPyJzvRFRGKILuSKiMQQhb6ISAxR6IuIxBCFvohIDFHoi4jEEIW+iEgM+f/UlWRG6yuFSgAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "sns.distplot(Totaldata['rating'], bins=15)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## We choose 'efficiency' to be our target and we divide the 'rating' column into two classes: $0$ if the rating is below $7$ and $1$ otherwise, which we use as one of our features." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "Totaldata['rating'] = (Totaldata['rating'] >6).astype(int)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### $\\color{blue}{\\text{10% of the data}}$" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "def get_data(data, percentage):\n", + " Random=list(range(data.shape[0]))\n", + " np.random.shuffle(Random)\n", + " data=data.iloc[Random]\n", + " return data.iloc[[i for i in range(int(percentage*len(data)))]]" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "ten_percent_data=get_data(Totaldata, 0.1)\n", + "\n", + "ten_percent_data=ten_percent_data[['sideEffects', 'sideEffectsReview',\\\n", + " 'commentsReview', 'rating', 'effectiveness']]\n", + "rating=ten_percent_data['rating']\n", + "ten_percent_data=ten_percent_data.drop('rating', axis=1)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "Features=ten_percent_data.drop(['effectiveness'], axis=1)\n", + "Target=ten_percent_data['effectiveness']\n", + "Target=le().fit_transform(Target)\n", + "\n", + "Dat=''\n", + "for col in Features.columns: \n", + " Dat += Features[col].map(str) + ' '" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1004 Mild Side Effects I experienced drowsiness in ...\n", + "163 Moderate Side Effects Joint pain, reduction of...\n", + "2128 Extremely Severe Side Effects These were sever...\n", + "1047 No Side Effects None experienced Applied every...\n", + "1838 Mild Side Effects Appetite seems to fluctuate,...\n", + "Name: sideEffects, dtype: object" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Dat.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "Text_tranform=CountVectorizer(analyzer='word', max_features=100, stop_words='english', binary=True).fit(Dat)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "Text_tranform.vocabulary_;" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "Numerical_features=Text_tranform.transform(Dat)\n", + "Numerical_features=Numerical_features.toarray()\n", + "Data=pd.DataFrame(Numerical_features) \n", + "\n", + "Data=pd.DataFrame(np.concatenate([rating.values.reshape(-1,1), Data], axis=1))\n", + "Data=pd.DataFrame(np.concatenate([Data, Target.reshape(-1,1)], axis=1))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
0123456789...9293949596979899100101
00100100000...0110100003
10000000000...0000000114
20000000010...0000000000
30000000000...0000000004
41000000000...0001001001
\n", + "

5 rows × 102 columns

\n", + "
" + ], + "text/plain": [ + " 0 1 2 3 4 5 6 7 8 9 ... 92 93 94 95 \\\n", + "0 0 1 0 0 1 0 0 0 0 0 ... 0 1 1 0 \n", + "1 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 \n", + "2 0 0 0 0 0 0 0 0 1 0 ... 0 0 0 0 \n", + "3 0 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 \n", + "4 1 0 0 0 0 0 0 0 0 0 ... 0 0 0 1 \n", + "\n", + " 96 97 98 99 100 101 \n", + "0 1 0 0 0 0 3 \n", + "1 0 0 0 1 1 4 \n", + "2 0 0 0 0 0 0 \n", + "3 0 0 0 0 0 4 \n", + "4 0 0 1 0 0 1 \n", + "\n", + "[5 rows x 102 columns]" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "Train_features, Test_features, Train_target, Test_target = train_test_split(Data.iloc[:, :-1],\\\n", + " Data.iloc[:, -1], test_size=0.4, random_state=0)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "weights=np.ones((len(np.unique(Train_target)), 1+Train_features.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=100, lr=0.3)" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "MultiLogReg.fit(Train_features, pd.Series(Train_target), weights)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "Predict=MultiLogReg.predict(Test_features)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{0, 1, 2, 3, 4}" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "set(Predict)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of Multiclass Logistic Regression: 46.98795180722892%\n" + ] + } + ], + "source": [ + "accuracy=(Test_target==Predict).sum()/len(Test_target)\n", + "print(\"Accuracy of Multiclass Logistic Regression: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [], + "source": [ + "NB=Naive_Bayes()\n", + "\n", + "NB.train(Train_features, pd.Series(Train_target))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "Pred=NB.predict(Test_features)" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of my Bernoulli Naive Bayes: 43.373493975903614%\n" + ] + } + ], + "source": [ + "accuracy=(Test_target==Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of my Bernoulli Naive Bayes: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "GDA_Model=GDAMulticlass(regularizer=0.1)\n", + "GDA_Model.train(pd.DataFrame(Train_features), pd.Series(Train_target, name='target'))" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "GDA_Pred=GDA_Model.predict(pd.DataFrame(Test_features))" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of GDA: 45.78313253012048%\n" + ] + } + ], + "source": [ + "accuracy=(Test_target==GDA_Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of GDA: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### $\\color{blue}{\\text{30% of the data}}$" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [], + "source": [ + "thirty_percent_data=get_data(Totaldata, 0.3)\n", + "\n", + "thirty_percent_data=thirty_percent_data[['sideEffects', 'sideEffectsReview', \\\n", + " 'commentsReview', 'rating', 'effectiveness']]\n", + "rating=thirty_percent_data['rating']\n", + "thirty_percent_data=thirty_percent_data.drop('rating', axis=1)\n", + "\n", + "Features=thirty_percent_data.drop(['effectiveness'], axis=1)\n", + "Target=thirty_percent_data['effectiveness']\n", + "Target=le().fit_transform(Target)\n", + "\n", + "Dat=''\n", + "for col in Features.columns: \n", + " Dat += Features[col].map(str) + ' '" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
0123456789...9293949596979899100101
01000000000...0000000004
10000000001...0000000003
21000000101...0010101101
31010000000...0011000001
41000000000...0000000001
\n", + "

5 rows × 102 columns

\n", + "
" + ], + "text/plain": [ + " 0 1 2 3 4 5 6 7 8 9 ... 92 93 94 95 \\\n", + "0 1 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 \n", + "1 0 0 0 0 0 0 0 0 0 1 ... 0 0 0 0 \n", + "2 1 0 0 0 0 0 0 1 0 1 ... 0 0 1 0 \n", + "3 1 0 1 0 0 0 0 0 0 0 ... 0 0 1 1 \n", + "4 1 0 0 0 0 0 0 0 0 0 ... 0 0 0 0 \n", + "\n", + " 96 97 98 99 100 101 \n", + "0 0 0 0 0 0 4 \n", + "1 0 0 0 0 0 3 \n", + "2 1 0 1 1 0 1 \n", + "3 0 0 0 0 0 1 \n", + "4 0 0 0 0 0 1 \n", + "\n", + "[5 rows x 102 columns]" + ] + }, + "execution_count": 33, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Text_tranform=CountVectorizer(analyzer='word', max_features=100, stop_words='english', binary=True).fit(Dat)\n", + "\n", + "Text_tranform.vocabulary_;\n", + "\n", + "Numerical_features=Text_tranform.transform(Dat)\n", + "Numerical_features=Numerical_features.toarray()\n", + "Data=pd.DataFrame(Numerical_features) \n", + "\n", + "Data=pd.DataFrame(np.concatenate([rating.values.reshape(-1,1), Data], axis=1))\n", + "Data=pd.DataFrame(np.concatenate([Data, Target.reshape(-1,1)], axis=1))\n", + "\n", + "Data.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "Train_features, Test_features, Train_target, Test_target = train_test_split(Data.iloc[:, :-1],\\\n", + " Data.iloc[:, -1], test_size=0.4, random_state=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "weights=np.ones((len(np.unique(Train_target)), 1+Train_features.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=100, lr=0.3)\n", + "\n", + "MultiLogReg.fit(Train_features, pd.Series(Train_target), weights)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of Multiclass Logistic Regression: 44.46680080482898%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Predict=MultiLogReg.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Predict).sum()/len(Test_target)\n", + "print(\"Accuracy of Multiclass Logistic Regression: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "NB=Naive_Bayes()\n", + "\n", + "NB.train(Train_features, pd.Series(Train_target))" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of my Bernoulli Naive Bayes: 43.05835010060362%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Pred=NB.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of my Bernoulli Naive Bayes: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "GDA_Model=GDAMulticlass(regularizer=0.01)\n", + "GDA_Model.train(pd.DataFrame(Train_features), pd.Series(Train_target, name='target'))" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of GDA: 44.668008048289735%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "GDA_Pred=GDA_Model.predict(pd.DataFrame(Test_features))\n", + "\n", + "accuracy=(Test_target==GDA_Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of GDA: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### $\\color{blue}{\\text{60% of the data}}$" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [], + "source": [ + "sixty_percent_data=get_data(Totaldata, 0.6)\n", + "\n", + "sixty_percent_data=sixty_percent_data[['sideEffects', 'sideEffectsReview', 'commentsReview', 'rating', 'effectiveness']]\n", + "rating=sixty_percent_data['rating']\n", + "sixty_percent_data=sixty_percent_data.drop('rating', axis=1)\n", + "\n", + "\n", + "\n", + "Features=sixty_percent_data.drop(['effectiveness'], axis=1)\n", + "Target=sixty_percent_data['effectiveness']\n", + "Target=le().fit_transform(Target)\n", + "\n", + "Dat=''\n", + "for col in Features.columns: \n", + " Dat += Features[col].map(str) + ' '" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [], + "source": [ + "Text_tranform=CountVectorizer(analyzer='word', max_features=100, stop_words='english', binary=True).fit(Dat)\n", + "\n", + "Text_tranform.vocabulary_;\n", + "\n", + "Numerical_features=Text_tranform.transform(Dat)\n", + "Numerical_features=Numerical_features.toarray()\n", + "Data=pd.DataFrame(Numerical_features) \n", + "\n", + "Data=pd.DataFrame(np.concatenate([rating.values.reshape(-1,1), Data], axis=1))\n", + "Data=pd.DataFrame(np.concatenate([Data, Target.reshape(-1,1)], axis=1))\n", + "\n", + "Data.head();" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "Train_features, Test_features, Train_target, Test_target = train_test_split(Data.iloc[:, :-1],\\\n", + " Data.iloc[:, -1], test_size=0.4, random_state=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "weights=np.ones((len(np.unique(Train_target)), 1+Train_features.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=100, lr=0.3)\n", + "\n", + "MultiLogReg.fit(Train_features, pd.Series(Train_target), weights)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of Multiclass Logistic Regression: 46.17706237424547%\n" + ] + } + ], + "source": [ + "Predict=MultiLogReg.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Predict).sum()/len(Test_target)\n", + "print(\"Accuracy of Multiclass Logistic Regression: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "NB=Naive_Bayes()\n", + "\n", + "NB.train(Train_features, pd.Series(Train_target))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of my Bernoulli Naive Bayes: 45.87525150905433%\n" + ] + } + ], + "source": [ + "Pred=NB.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of my Bernoulli Naive Bayes: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "GDA_Model=GDAMulticlass(regularizer=0.1)\n", + "GDA_Model.train(pd.DataFrame(Train_features), pd.Series(Train_target, name='target'))" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of GDA: 48.08853118712273%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "GDA_Pred=GDA_Model.predict(pd.DataFrame(Test_features))\n", + "\n", + "accuracy=(Test_target==GDA_Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of GDA: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### $\\color{blue}{\\text{100% of the data}}$" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "whole_data=get_data(Totaldata, 1.0)\n", + "\n", + "whole_data=whole_data[['sideEffects', 'sideEffectsReview', 'commentsReview', 'rating', 'effectiveness']]\n", + "rating=whole_data['rating']\n", + "whole_data=whole_data.drop('rating', axis=1)\n", + "\n", + "\n", + "\n", + "Features=whole_data.drop(['effectiveness'], axis=1)\n", + "Target=whole_data['effectiveness']\n", + "Target=le().fit_transform(Target)\n", + "\n", + "Dat=''\n", + "for col in Features.columns: \n", + " Dat += Features[col].map(str) + ' '\n" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "Text_tranform=CountVectorizer(analyzer='word', max_features=100, stop_words='english', binary=True).fit(Dat)\n", + "\n", + "Text_tranform.vocabulary_;\n", + "\n", + "Numerical_features=Text_tranform.transform(Dat)\n", + "Numerical_features=Numerical_features.toarray()\n", + "Data=pd.DataFrame(Numerical_features) \n", + "\n", + "#Data=pd.DataFrame(np.concatenate([rating.values.reshape(-1,1), Data], axis=1))\n", + "Data=pd.DataFrame(np.concatenate([Data, Target.reshape(-1,1)], axis=1))\n", + "\n", + "Data.head();\n" + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": {}, + "outputs": [], + "source": [ + "Train_features, Test_features, Train_target, Test_target = train_test_split(Data.iloc[:, :-1],\\\n", + " Data.iloc[:, -1], test_size=0.4, random_state=0)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "weights=np.ones((len(np.unique(Train_target)), 1+Train_features.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=100, lr=0.3)\n", + "\n", + "MultiLogReg.fit(Train_features, pd.Series(Train_target), weights)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 54, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of Multiclass Logistic Regression: 41.61640530759952%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Predict=MultiLogReg.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Predict).sum()/len(Test_target)\n", + "print(\"Accuracy of Multiclass Logistic Regression: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [], + "source": [ + "NB=Naive_Bayes()\n", + "\n", + "NB.train(Train_features, pd.Series(Train_target))" + ] + }, + { + "cell_type": "code", + "execution_count": 56, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of my Bernoulli Naive Bayes: 39.56574185765983%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Pred=NB.predict(Test_features)\n", + "\n", + "accuracy=(Test_target==Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of my Bernoulli Naive Bayes: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "GDA_Model=GDAMulticlass(regularizer=0.1)\n", + "GDA_Model.train(pd.DataFrame(Train_features), pd.Series(Train_target, name='target'))" + ] + }, + { + "cell_type": "code", + "execution_count": 58, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of GDA: 42.5211097708082%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "GDA_Pred=GDA_Model.predict(pd.DataFrame(Test_features))\n", + "\n", + "accuracy=(Test_target==GDA_Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of GDA: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Comparison using the Iris data" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [], + "source": [ + "from sklearn import datasets\n", + "iris=datasets.load_iris()\n", + "\n", + "x=iris.data[:,:4]\n", + "y=(iris.target)" + ] + }, + { + "cell_type": "code", + "execution_count": 60, + "metadata": {}, + "outputs": [], + "source": [ + "x_train, x_test, y_train, y_test = train_test_split(x,\\\n", + " y, test_size=0.8, random_state=101)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "weights=np.zeros((len(np.unique(y)), 1+x.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=400, lr=0.2)\n", + "\n", + "MultiLogReg.fit(pd.DataFrame(x_train), pd.Series(y_train), weights)" + ] + }, + { + "cell_type": "code", + "execution_count": 62, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "Ypred=MultiLogReg.predict(x_test)" + ] + }, + { + "cell_type": "code", + "execution_count": 63, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Accuracy of Logistic regression: 97.5%'" + ] + }, + "execution_count": 63, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "(\"Accuracy of Logistic regression: {}%\" .format(100*(Ypred==y_test).sum()/len(y_test)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [], + "source": [ + "NaiveB=Naive_Bayes()\n", + "NaiveB.train(pd.DataFrame(x_train), pd.Series(y_train))" + ] + }, + { + "cell_type": "code", + "execution_count": 65, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "Y1pred=NaiveB.predict(pd.DataFrame(x_test))" + ] + }, + { + "cell_type": "code", + "execution_count": 66, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of Naive Bayes: 35.833333333333336%\n" + ] + } + ], + "source": [ + "print('Accuracy of Naive Bayes: {}%' .format (100*(Y1pred==y_test).sum()/len(y_test)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 67, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "GDA2=GDAMulticlass()\n", + "GDA2.train(pd.DataFrame(x_train), pd.Series(y_train, name='target'))" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]\n" + ] + } + ], + "source": [ + "Y2Pred=GDA2.predict(pd.DataFrame(x_test))" + ] + }, + { + "cell_type": "code", + "execution_count": 69, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of GDA: 98.33333333333333%\n" + ] + } + ], + "source": [ + "print(\"Accuracy of GDA: {}%\" .format(100*(Y2Pred==y_test).sum()/len(y_test)))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### We download another data to compare the three models." + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [], + "source": [ + "#!wget https://storage.googleapis.com/dataset-uploader/bbc/bbc-text.csv" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "metadata": {}, + "outputs": [ + { + "data": { + "text/html": [ + "
\n", + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
categorytext
0techtv future in the hands of viewers with home th...
1businessworldcom boss left books alone former worldc...
2sporttigers wary of farrell gamble leicester say ...
3sportyeading face newcastle in fa cup premiership s...
4entertainmentocean s twelve raids box office ocean s twelve...
\n", + "
" + ], + "text/plain": [ + " category text\n", + "0 tech tv future in the hands of viewers with home th...\n", + "1 business worldcom boss left books alone former worldc...\n", + "2 sport tigers wary of farrell gamble leicester say ...\n", + "3 sport yeading face newcastle in fa cup premiership s...\n", + "4 entertainment ocean s twelve raids box office ocean s twelve..." + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Text=pd.read_csv(\"bbc-text.csv\")\n", + "Text.head()" + ] + }, + { + "cell_type": "code", + "execution_count": 72, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'tv future in the hands of viewers with home theatre systems plasma high-definition tvs and digital video recorders moving into the living room the way people watch tv will be radically different in five years time. that is according to an expert panel which gathered at the annual consumer electronics show in las vegas to discuss how these new technologies will impact one of our favourite pastimes. with the us leading the trend programmes and other content will be delivered to viewers via home networks through cable satellite telecoms companies and broadband service providers to front rooms and portable devices. one of the most talked-about technologies of ces has been digital and personal video recorders (dvr and pvr). these set-top boxes like the us s tivo and the uk s sky+ system allow people to record store play pause and forward wind tv programmes when they want. essentially the technology allows for much more personalised tv. they are also being built-in to high-definition tv sets which are big business in japan and the us but slower to take off in europe because of the lack of high-definition programming. not only can people forward wind through adverts they can also forget about abiding by network and channel schedules putting together their own a-la-carte entertainment. but some us networks and cable and satellite companies are worried about what it means for them in terms of advertising revenues as well as brand identity and viewer loyalty to channels. although the us leads in this technology at the moment it is also a concern that is being raised in europe particularly with the growing uptake of services like sky+. what happens here today we will see in nine months to a years time in the uk adam hume the bbc broadcast s futurologist told the bbc news website. for the likes of the bbc there are no issues of lost advertising revenue yet. it is a more pressing issue at the moment for commercial uk broadcasters but brand loyalty is important for everyone. we will be talking more about content brands rather than network brands said tim hanlon from brand communications firm starcom mediavest. the reality is that with broadband connections anybody can be the producer of content. he added: the challenge now is that it is hard to promote a programme with so much choice. what this means said stacey jolna senior vice president of tv guide tv group is that the way people find the content they want to watch has to be simplified for tv viewers. it means that networks in us terms or channels could take a leaf out of google s book and be the search engine of the future instead of the scheduler to help people find what they want to watch. this kind of channel model might work for the younger ipod generation which is used to taking control of their gadgets and what they play on them. but it might not suit everyone the panel recognised. older generations are more comfortable with familiar schedules and channel brands because they know what they are getting. they perhaps do not want so much of the choice put into their hands mr hanlon suggested. on the other end you have the kids just out of diapers who are pushing buttons already - everything is possible and available to them said mr hanlon. ultimately the consumer will tell the market they want. of the 50 000 new gadgets and technologies being showcased at ces many of them are about enhancing the tv-watching experience. high-definition tv sets are everywhere and many new models of lcd (liquid crystal display) tvs have been launched with dvr capability built into them instead of being external boxes. one such example launched at the show is humax s 26-inch lcd tv with an 80-hour tivo dvr and dvd recorder. one of the us s biggest satellite tv companies directtv has even launched its own branded dvr at the show with 100-hours of recording capability instant replay and a search function. the set can pause and rewind tv for up to 90 hours. and microsoft chief bill gates announced in his pre-show keynote speech a partnership with tivo called tivotogo which means people can play recorded programmes on windows pcs and mobile devices. all these reflect the increasing trend of freeing up multimedia so that people can watch what they want when they want.'" + ] + }, + "execution_count": 72, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "Text.text[0]" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 74, + "metadata": {}, + "outputs": [], + "source": [ + "Text_tranformer=CountVectorizer(analyzer='word', max_features=400, binary=True).fit(Text['text'])\n", + "\n", + "bow1=Text_tranformer.transform(Text['text'])" + ] + }, + { + "cell_type": "code", + "execution_count": 75, + "metadata": {}, + "outputs": [], + "source": [ + "Data=pd.DataFrame(data=bow1.toarray())\n", + "Data.head()\n", + "Text['category']=le().fit_transform(Text['category'])\n", + "Data['target']=Text['category']" + ] + }, + { + "cell_type": "code", + "execution_count": 76, + "metadata": {}, + "outputs": [], + "source": [ + "Train_features, Test_features, Train_target, Test_target = train_test_split(Data.iloc[:, :-1],\\\n", + " Data.iloc[:, -1], test_size=0.4, random_state=101)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Multiclass\\ Logistic\\ Regression}$" + ] + }, + { + "cell_type": "code", + "execution_count": 77, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "weights=np.ones((len(np.unique(Train_target)), 1+Train_features.shape[1]))\n", + "\n", + "MultiLogReg=MulticlassLogReg(Max_iter=100, lr=0.2)\n", + "\n", + "MultiLogReg.fit(Train_features, Train_target, weights)" + ] + }, + { + "cell_type": "code", + "execution_count": 78, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of the Logistic-Regression: 93.14606741573034\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Predict=MultiLogReg.predict(Test_features)\n", + "AccuracyLogRegression=(Predict==Test_target).sum()/(len(Test_target))\n", + "print(\"Accuracy of the Logistic-Regression: \", AccuracyLogRegression*100)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Bernoulli\\ Naive\\ Bayes}$" + ] + }, + { + "cell_type": "code", + "execution_count": 79, + "metadata": {}, + "outputs": [], + "source": [ + "NB=Naive_Bayes()\n", + "\n", + "NB.train(Train_features, Train_target)" + ] + }, + { + "cell_type": "code", + "execution_count": 80, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy Naive Bayes: 86.62921348314607%\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "Pred=NB.predict(Test_features)\n", + "\n", + "accuracy=(np.array(Test_target)==Pred).sum()/len(Test_target)\n", + "print(\"Accuracy Naive Bayes: {}%\".format(100*accuracy))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$\\color{blue}{Gaussian\\ Discriminant\\ Analysis}$" + ] + }, + { + "cell_type": "code", + "execution_count": 81, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " training: [=======================================100.0%=======================================]\n" + ] + } + ], + "source": [ + "MulticlassGDA=GDAMulticlass()\n", + "\n", + "MulticlassGDA.train(Train_features, Train_target)" + ] + }, + { + "cell_type": "code", + "execution_count": 82, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + " predictions: [=====================================100.0%======================================]" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Accuracy of the GDA: 93.37078651685393\n" + ] + }, + { + "name": "stderr", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "GDA_Pred=MulticlassGDA.predict(Test_features)\n", + "\n", + "AccuracyGDA=(np.array(Test_target)==GDA_Pred).sum()/len(Test_target)\n", + "print(\"Accuracy of the GDA: \", AccuracyGDA*100)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## $\\color{green}{\\text{Report}}$" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The three algorithms GDA, Naive Bayes and Softmax Logistic Regression were compared on three different data sets: 'drugLib_raw.tsv', Iris data set and 'bbc-text.csv'.\n", + "The comparison on the first data set 'drugLib_raw.tsv' was done in four steps: comparison on $10\\%$, $30\\%$, $60\\%$ and finally on $100\\%$ of the data. On these four comparisons, GDA appeared to be the most accurate (even though the accuracy was around $45\\%$ in average), followed very closely by Softmax Logistic Rgression. But it is important to underline that Naive Bayes and GDA are very fast (during the training process) as compared to Softmax Logistic Regression. This is due to the fact that GDA and Naive Bayes are both generative models and don't require any learning algorithm, their parameters are directly computed, no update required. On the other side, the low accuracy observed on the three algorithms is probably due to the fact that the features used are not predictive enough for the target chosen.\n", + "\n", + "\n", + "\n", + "On Iris data set (small data set), very good accuracy was observed but only on two of the three algorithms. Again, GDA and Softmax Logistic Regression were the best ($98.33\\%$ vs $97.5\\%$), whereas Naive Bayes gave $35.83\\%$ accuracy. The failure of Naive Bayes (actually Bernoulli Naive Bayes) on this example is due to the fact that features were not binary.\n", + "\n", + "On the third data set, which also is as big as the first one, we observed good accuracy for the three algorithms. On this particular data set, Softmax was slightly less accurate as compared to GDA ($93.15\\%$ vs $93.37\\%$) and Naive Bayes scored $86.63\\%$.\n", + "\n", + "\n", + "In conclusion, each of the three algorithms is unique and reliable depending on which data we are investigating. The two generative models GDA and Naive Bayes are fast but can give bad results if the (strong) assumptions they are made of are not met. On the other side, Softmax Logistic Regression takes time to train, but is more stable as it uses fewer assumptions and can handle both binary and non-binary features." + ] + }, + { + "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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/.ipynb_checkpoints/My_binary_search_from_scratch-checkpoint.ipynb b/.ipynb_checkpoints/My_binary_search_from_scratch-checkpoint.ipynb new file mode 100644 index 0000000..5ad1bbf --- /dev/null +++ b/.ipynb_checkpoints/My_binary_search_from_scratch-checkpoint.ipynb @@ -0,0 +1,115 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Length of the current array: 12\n", + "Length of the current array: 6\n", + "Length of the current array: 2\n", + "Length of the current array: 1\n", + "\n", + "-1\n", + "\n", + "Length of the current array: 12\n", + "Length of the current array: 5\n", + "Length of the current array: 2\n", + "\n", + "8\n" + ] + } + ], + "source": [ + "\"\"\"You're going to write a binary search function.\n", + "You should use an iterative approach - meaning\n", + "using loops.\n", + "Your function should take two inputs:\n", + "a Python list to search through, and the value\n", + "you're searching for.\n", + "Assume the list only has distinct elements,\n", + "meaning there are no repeated values, and \n", + "elements are in a strictly increasing order.\n", + "Return the index of value, or -1 if the value\n", + "doesn't exist in the list.\"\"\"\n", + "import numpy as np\n", + "\n", + "def binary_search_helper(input_array):\n", + " \"\"\"Your code goes here.\"\"\"\n", + " n=len(input_array)\n", + " even=False\n", + " if n%2==0:\n", + " center=n//2\n", + " even=True\n", + " else:\n", + " center=(n-1)//2\n", + " return center, even\n", + " \n", + "def binary_search(input_array_, value):\n", + " input_array=input_array_.copy()\n", + " index=-1\n", + " Search=True\n", + " center=binary_search_helper(input_array)[0]\n", + " position=center\n", + " while(index==-1 and Search):\n", + " print(\"Length of the current array:\",len(input_array))\n", + " if input_array[center]>value:\n", + " input_array=input_array[:center]\n", + " center, even_left=binary_search_helper(input_array)\n", + " if even_left:\n", + " position -= center\n", + " else:\n", + " position -= center+1\n", + " elif input_array[center] -len(digits):\n", + " digits[i] = 0\n", + " digits[i-1] += 1\n", + " i -= 1\n", + " if digits[i] != 10:\n", + " break\n", + " if digits[0] == 10:\n", + " digits = [int(\" \".join(str(digits[0])).split()[0]), int(\" \".join(str(digits[0])).split()[1])] + digits[1:]\n", + " return digits\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "Dig = [1,9,9]" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 0, 0]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "plusOne(Dig)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "def findDiagonalOrder(matrix):\n", + " if len(matrix) == 0:\n", + " return []\n", + " else:\n", + " N, M = len(matrix), len(matrix[0])\n", + " Traversal = []\n", + " Down = False\n", + " for n in range(N+M-1):\n", + " if Down:\n", + " for c in range(n+1):\n", + " if c >= N or n-c >= M:\n", + " continue\n", + " Traversal.append(matrix[c][n-c])\n", + " else:\n", + " for c in range(n+1)[::-1]:\n", + " if c >= N or n-c >= M:\n", + " continue\n", + " Traversal.append(matrix[c][n-c])\n", + " Down = not Down\n", + " return Traversal" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "M=np.array([[2,3,-6,1], [39,-2,9.7, 3], [11,9,34, 100]])" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2.0, 3.0, 39.0, 11.0, -2.0, -6.0, 1.0, 9.7, 9.0, 34.0, 3.0, 100.0]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "findDiagonalOrder(M)" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "def longestCommonPrefix(strs):\n", + " if strs == [] or strs == [\"\"]:\n", + " return \"\"\n", + " if len(strs) == 1:\n", + " return strs[0]\n", + " prefix = \"\"\n", + " position = 0\n", + " while True:\n", + " if strs[0] == \"\":\n", + " return \"\"\n", + " item0 = strs[0]\n", + " if position < len(item0):\n", + " caracter = item0[position]\n", + " for item in strs:\n", + " if item == \"\" or item[0] == \"\":\n", + " return \"\"\n", + " if position >= len(item) or item[position] != caracter:\n", + " return prefix\n", + " prefix += caracter\n", + " position += 1" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "def twoSum1(numbers, target):\n", + " D={}\n", + " for i in range(len(numbers)):\n", + " if target - numbers[i] in D:\n", + " return [D[target - numbers[i]]+1, i+1]\n", + " D[numbers[i]]=i" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "def twoSum2(numbers, target):\n", + " i = 0\n", + " j = i+1\n", + " while numbers[i] + numbers[j] != target:\n", + " while numbers[i] + numbers[j] < target:\n", + " if j < len(numbers)-1:\n", + " j += 1\n", + " else:\n", + " break\n", + " if numbers[i] + numbers[j] == target:\n", + " return [i+1, j+1]\n", + " i += 1\n", + " j = i+1\n", + " return [i+1, j+1]" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "numbers = [-19,-10,4,389,394,419,429,529,576,618,619,714,802,1113,4223,6789]\n", + "target = 6779" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 16]" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "twoSum1(numbers, target)" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 16]" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "twoSum2(numbers, target)" + ] + }, + { + "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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}