diff --git a/Crash Course on Naive Bayes Classification/Product Recommendations/iHealth_R_code_notebook.ipynb b/Crash Course on Naive Bayes Classification/Product Recommendations/iHealth_R_code_notebook.ipynb new file mode 100644 index 0000000..7676c55 --- /dev/null +++ b/Crash Course on Naive Bayes Classification/Product Recommendations/iHealth_R_code_notebook.ipynb @@ -0,0 +1,115 @@ +{ + "cells": [ + { + "attachments": {}, + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Can Naïve Bayes models be used to provide new product recommendations for FitBits?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#Prepare a clean R environment in work space.\n", + "rm(list=ls())" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#Import our csv file data\n", + "data=read.csv(\"iHealthdata.csv\")\n", + "names(data)=c(\"Main Interest\",\"Current Exercise Level\", \"How Motivated\", \"Comfortable with tech Devices?\", \"Model #\")" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "#Use the NB classifier on test Data\n", + "iHealth_classifier=function(interest,exercise,motivation,comfortlevel){\n", + " #interest='health'\n", + " #exercise='moderate'\n", + " #motivation='moderate'\n", + " #comfortlevel='yes'\n", + " \n", + " vars=c(interest,exercise,motivation,comfortlevel)\n", + " #data=read.table(\"i-01.txt\")\n", + " data=read.csv(\"iHealthdata.csv\")\n", + " names(data)=c(\"Main Interest\",\"Current Exercise Level\", \"How Motivated\", \"Comfortable with tech Devices?\", \"Model #\")\n", + " \n", + " uniquevec=unique(data$'Model #') #Unique Model Choices\n", + " val=length(uniquevec)\n", + " \n", + " ProbMat=matrix(0,(dim(data)[2]),val) \n", + " \n", + " #compute probabilities\n", + " for (i in 1:(dim(ProbMat)[1])){\n", + " for (j in 1:val){\n", + " data_cond=subset(data,data$`Model #`==uniquevec[j]) #Model type\n", + " \n", + " if (i