Commit bf6747a8 by Sanghoon

Upload New File

parent bb485387
{
"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<dim(ProbMat)[1]){\n",
" probval=dim(subset(data_cond,data_cond[,i]==vars[i]))[1]/dim(data_cond)[1]} #Compute probability of model being chosen\n",
" \n",
" else\n",
" \n",
" {probval=dim(data_cond)[1]/dim(data)[1]} #Compute marginal probabilities\n",
" \n",
" ProbMat[i,j]=probval\n",
" }\n",
" \n",
" }\n",
" \n",
" finalvec=apply(ProbMat,2,prod)\n",
" finalval=which.max(finalvec)\n",
" choice=uniquevec[finalval]\n",
" return(list(ProbMat=ProbMat,finalvec=finalvec,choice=choice))\n",
"}\n",
"\n",
"#}\n",
"#data_i100=subset(data,data$`Model #`=='i100')\n",
"\n",
"\n",
"#data_i500=subset(data,data$`Model #`=='i500')}\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [],
"source": [
"#Executing function in a sample data set to provide new product recommendations\n",
"Ex1<-iHealth_classifier(interest=\"both\",exercise=\"active\",motivation =\"aggressive\",comfortlevel = \"yes\")\n",
"Ex2<-iHealth_classifier(interest=\"appearance\",exercise=\"sedentary\",motivation =\"moderate\",comfortlevel = \"yes\")\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "R",
"language": "R",
"name": "ir"
},
"language_info": {
"codemirror_mode": "r",
"file_extension": ".r",
"mimetype": "text/x-r-source",
"name": "R",
"pygments_lexer": "r",
"version": "3.4.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
  • Excellent update on this commit. It’s clear you’re polishing the tutorial with care and a clear direction in mind. For anyone curious about how AI can be used to improve visuals or educational materials, tools like the ones highlighted at https://remnimodapk.com/ can be very useful for producing sharper, more engaging content.

  • IPTV Strong delivers a reliable, modern way to enjoy television through the internet. With stable streaming, high-quality channels, and flexible device support, IPTV Strong suits viewers who value convenience and variety. Users can access live TV, movies, and series without traditional cables. It emphasizes smooth performance, fast loading, and easy setup, making entertainment accessible, efficient, and adaptable to today’s digital lifestyle.

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment