Guided Selling using R

Posted on Updated on

# Setting current working directory
getwd()
setwd("D:/R")
getwd()
# Read data from Last.FM frequency matrix
data.germany head(data.germany[,c(1,3:8)])

# Drop the user column and make a new data frame
data.germany.ibs

# Create a helper function to calculate the cosine between two vectors
getCosine {
this.cosine return(this.cosine)
}

# Create a placeholder dataframe listing item vs. item
holder data.germany.ibs.similarity

# Lets fill in those empty spaces with cosine similarities
for(i in 1:ncol(data.germany.ibs)) {
for(j in 1:ncol(data.germany.ibs)) {
data.germany.ibs.similarity[i,j]= getCosine(data.germany.ibs[i],data.germany.ibs[j])
}
}

# Output similarity results to a file
write.csv(data.germany.ibs.similarity,file="final-germany-similarity.csv")

# Get the top 10 neighbours for each
data.germany.neighbours

for(i in 1:ncol(data.germany.ibs))
{
data.germany.neighbours[i,] }

# Output neighbour results to a file
write.csv(file="final-germany-item-neighbours.csv",x=data.germany.neighbours[,-1])
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s