Pages

Introduction to Recommendation Systems

Monday, October 5, 2009


Hi all,

Let's begin another article's series. Now i will talk about recommendation systems and how we can implement some simple recommendation algorithms using information filtering with functional examples. You probably already came into recommendation systems but you didn't know.

There are some examples: Amazon, Netflix, etc. They generally register the user preference and based on this profile, it uses it (the information inside it) to suggest new products that you may like. It's a powerful system and you can use it to build systems that find people that have the same preference as you or make automatic suggestions based on preferences and tastes that other people like.

To start, let's introduce what's a recommendation system.

1 - Recommender Systems

"A recommender system can be defined as "any system that produces individualized recommendations as output or has the effect of guiding the user in a personalized way to interesting or useful objects in a large space of possible options. " (Burke 2002).

The problem being addressed is that "too much information", challenging those in search of something to find that which is interesting within the vast array available.
From wikipedia we can see the following definition:

"Recommender systems form a specific type of information filtering (IF) technique that attempts to present information items (movies, music , books , news images, web pages, etc.) that are likely of interest to the user. Typically, a recommender system compares the user's profile to some reference characteristics, and seeks to predict the 'rating' that a user would give to an item they had not yet considered. These characteristics may be from the information item (the content-based approach) or the user's social environment (the collaborative filtering approach).

Recommender systems have been around since the early nineties and have evolved to meet the needs of e-commerce, research, museums and collections, digital libraries and entertainment. The volume of literature on recommender systems seems to be becoming as large as the problem itself and a high level model was proposed in order to find a path through this array of information and to guide the selection of information about recommender systems. The Figure 1 shows the main elements of a recommender system and describes the nature of the links between the elements.


Figure 01. Recommendation Systems Schemma

Recommendation is carried out by some kind of recommendation engine which employs a set of algorithms to compare a user profile with a set of reference characteristics. There are three types of source for the reference characteristics: Information about the items themselves (content), information about the social environment (collaborative) and information about the web usage (web analytics). Actually many tools use a mix of these techniques and they are a set of the information filtering systems.

Information Filtering System is a system that removes redundant or unwanted information from an information stream using (semi) automated methods in order to present to a human user. In the recommendation systems context, to do this the user's profile is compared to some reference characteristics as the content-based approach or the user's social environment (collaborative filtering approach). In the next section we will see those types of Information Filtering (IF).

2 - Information Filtering (IF)

2.1- Content-based-Filtering

Content based filtering uses information about the items to make recommendations. It will recommend items to a user if the items are similar in content to items that the user liked in the past. This approach allows recommendation of previously unrated items to users with unique interests and can provide explanations for its recommendations. As long as the system has some information about an item, recommendations can be mad even if the system has received a small number of ratings, or none at all. The disadvantage of this mechanism is that each item must be characterized with respect to the features that appear in the user's profile requiring modelling of each user's profile.

2.2- Collaborative Filtering

Collaborative filtering makes predictions about the interests of a user by collecting the choices or expressions of taste from many users. It finds areas of agreement between people and bases recommendations on the assumption that people who agreed in the past are likely to do so in the future. It looks for users who share the same ratings patterns with the active user, a neighbourhood of similar users, and uses their ratings to create a prediction. Unlike content-based filtering, it doesn't need to know anything about the item themselves, only people's opinions about the items.

Collaborative filtering may be based on the explicit ratings of users or on implicit observation of user behaviour. User behaviour is observed and compared to the behaviour of other users, for example, items purchased, queries made, items printed, or music listened to. Predictions can then be made about a user's future behaviour assuming like-mindedness in the past as a predictor for future patterns of behaviour.

There are two problems in this system of users and ratings: the 'first-rater problem' and 'cold-start problem'. The first-rater problem occurs when a new item goes into the system and has not yet received any ratings, preventing it from being recommended. The cold-start problem occurs for new users, about whom there is insufficient information from their active ratings or observed behaviour with which to predict their preferences.

Now that we presented some popular IF techniques, let's go further through those methods and see them in action. In the next article i will present some filtering techniques with their implementation on Python programming language.

Stay tunned!

Marcel Pinheiro Caraciolo

References

[1] http://en.wikipedia.org/wiki/Recommender_systems

[2] http://en.wikipedia.org/wiki/Information_filtering

[3] http://en.wikipedia.org/wiki/Collaborative_filtering

Particle Swarm Optimization (PSO) running on CellPhones (Symbian + 5800Xpress)

Tuesday, September 29, 2009


Hi all,

Have you ever imagined running optimization algorithms like genetic algorithms or particle swarm optimization on portable devices like cellphones ?

So, let me say that it's possible! First of all, one excellent work on running genetic algorithms on devices like Sony PSP and Symbian Phones was done by Christian Perone, author of the PyEvolve Framework (Python Genetic Algorithms Framework) written all in Python!

His work inspired me to port my old undergraduate project, the particle swarm optimization algorithm implementation in Java to Python! I decided to develop it from scratch and now it's almost complete for its first official release: The PyPSO Toolbox. You can take a look at the project and the source at its official home page repository.

Soon, it will be official available! Until there, i am doing some tests with the framework, correcting some bugs, documenting the source code, etc. But i was wondering here if it's possible to run also the PyPSO framework in the cellphone, like the Symbian Nokia 5800 XpressMusic.

Using the new version of the PyS60, the release 1.9.7, which comes with the new 2.5.1 Python core, I've executed the PyPSO toolbox without problems, and i was very amazed by the good performance of the PSO on the Nokia 5800, the problem that i ran was the minimization of one of the De Jogn's test suite functions, the Sphere function. The function is very simple as you can see its plot below at 3-D chart:

I've used particles with 5 dimmensions each with real values between the interval of [-5.12, 5.12], the Constricted Factor and the Global Topology of the PyPSO framework. Also i've set a population size of 30 particles.

After 36 iterations (about 12 seconds), the PSO execution ended with the best fitness of 0.0, representing the optimal solution (the minimum) of the De Jong's Sphere function.

Follow some screenshots of the simulation (click on the pictures to enlarge):





How to install PyPSO on the PyS60 ?

1) First, you need to install the PyS60 runtime for your Symbian platform. You can see more information about how to install it here.

2) Then, you must create a directory on your Memory Card or Phone Memory (Depends on where you installed the Python Script Shell), inside the "Python" directory, named "lib" , and inside this directory, you copy the "pypso" folder. The absolute folder structure will be like this:

C:\Python\lib\pypso or E:\Python\lib\pypso

Some features of the framework will not work, like some report Adapters, however, the PSO core is working really great. I've used the PyPSO subversion release 0.11. Since it's not finished yet, you can download from the subversion repository from here.

Here is the source code I've used to minimize the De Jong's Sphere function (Special thanks to Christian Perone who inspired me to do this work) :


"""
PyPsoS60Demo.py
Author: Marcel Pinheiro Caraciolo
caraciol@gmail.com
License: GPL3
"""
BLUE = 0x0000ff
RED = 0xff0000
BLACK = 0x000000
WHITE = 0xffffff


import e32, graphics, appuifw
print "Loading PyPSO modules... ",
e32.ao_yield()

from pypso import Particle1D
from pypso import GlobalTopology
from pypso import Pso
from pypso import Consts

img = None
coords = []
graphMode = False
canvas = None
w = h = 0
print " done !"
e32.ao_yield()

def handle_redraw(rect):
if img is not None:
canvas.blit(img)


def sphere(particle):
total = 0.0
for value in particle.position:
total += (value ** 2.0)

return total

def pso_callback(pso_engine):
it = pso_engine.getCurrentStep()
best = pso_engine.bestParticle()
if graphMode:
img.clear(BLACK)
img.text((5, 15), u"Iteration %d - Best Fitness: %.2f" % (it,best.ownBestFitness), WHITE, font=('normal', 14, appuifw.STYLE_BOLD))
img.line((int(w/2),0,int(w/2),h),WHITE)
img.line((0,int(h/2),w,int(h/2)),WHITE)

cx = int(w/2) / int(best.getParam("rangePosmax"))
cy = int(-h/2) / int(best.getParam("rangePosmax"))

for particle in pso_engine.topology:
img.point([int(cx*particle.position[0]+ (w/2)),int(cy*particle.position[1]+(h/2)),5,5],BLUE,width=4)
img.point([int(cx*best.ownBestPosition[0]+ (w/2)),int(cy*best.ownBestPosition[1]+(h/2)),5,5],RED,width=4)
handle_redraw(())
else:
print "Iteration %d - Best Fitness: %.2f" % (it, best.ownBestFitness)
e32.ao_yield()

return False


def showBestParticle(best):
global graphMode

if graphMode:
img.clear(BLACK)
img.text((5, 15), u"Best particle fitness: %.2f" % best.ownBestFitness, WHITE, font=('normal', 14, appuifw.STYLE_BOLD))
img.line((int(w/2),0,int(w/2),h),WHITE)
img.line((0,int(h/2),w,int(h/2)),WHITE)
cx = int(w/2) / int(best.getParam("rangePosmax"))
cy = int(-h/2) / int(best.getParam("rangePosmax"))
img.point([int(cx*best.ownBestPosition[0]+ (w/2)),int(cy*best.ownBestPosition[1]+(h/2))],RED,width=7)
handle_redraw(())
e32.ao_sleep(4)
else:
print "\nBest particle fitness: %.2f" % (best.ownBestFitness,)


if __name__ == "__main__":
global graphMode, canvas, w, h

data = appuifw.query(u"Do you want to run on graphics mode ?", "query")

graphMode = data or False

if graphMode:
canvas = appuifw.Canvas(redraw_callback=handle_redraw)
appuifw.app.body = canvas
appuifw.app.screen = 'full'
appuifw.app.orientation = 'landscape'
w,h = canvas.size
img = graphics.Image.new((w,h))
img.clear(BLACK)
handle_redraw(())
e32.ao_yield()

#Parameters
dimmensions = 5
swarm_size = 30
timeSteps = 100

particleRep = Particle1D.Particle1D(dimmensions)
particleRep.setParams(rangePosmin=-5.12, rangePosmax=5.13, rangeVelmin=-5.12, rangeVelmax=5.13, bestFitness= 0.0 ,roundDecimal=2)
particleRep.evaluator.set(sphere)

topology = GlobalTopology.GlobalTopology(particleRep)
pso = Pso.SimplePSO(topology)
pso.setTimeSteps(timeSteps)
pso.setPsoType(Consts.psoType["CONSTRICTED"])
pso.terminationCriteria.set(Pso.FitnessScoreCriteria)
pso.stepCallback.set(pso_callback)
pso.setSwarmSize(swarm_size)

pso.execute()

best = pso.bestParticle()
showBestParticle(best)

To make things more interesting, i've decided to put a simple graphic mode, when the user can choose to see the simulation in graphics mode or console mode. So as soon as you start the PyPsoS60Demo.py script, a dialog will show up to ask which mode the user prefer to see the simulation. You can see the video of the graphics mode running below.




Each point is a particle and they're updating their position through the simulation and since the best optimal solution of the problem is the point (0,0), in the end of the simulation, the particles will be close to the best solution. You can see that the red point is the best particle of all swarm.

You can note at the source code the use of the module "e32" of the PyS60, this is used to process pending events, so we can follow the statistics of the current iteration while it evolves.

I hope you enjoyed this work, the next step is to port the Travelling Salesman Problem to cellphone!

You can download the script above here.

Marcel Pinheiro Caraciolo

Artificial Intelligence goes Mobile



Hi Folks,

I' am Marcel Pinheiro Caraciolo, master degree candidate at Federal University of Pernambuco (CIN/UFPE) located at Recife - Pernambuco - Brazil. As you can see, i am one of the main authors of the A.I. In Motion Blog (funny but the only one who posts here, but this is not the case!). My interests are about artificial intelligence and mobile computing. How to connect them is my daily work and my master thesis will be specific about data mining algorithms (as you saw in the last posts about data mining) and recommendation systems targeted to Mobile devices. On a next post i will talk further about it.

But, in general, one of my goals at my master degree thesis is to study and apply artificial intelligence and data mining algorithms into mobile computing, solving problems or turning possible those machine learning algorithms to offer their results or run them into small and limited processing devices like cell phones.



Let's build real Smart Phones!!


For inspiring our readers to read more about artificial intelligence and mobile computing connected, i've found this article in the internet: "The Artificial Intelligence goes Mobile" An excellent reading for people who wants to inspire themselves and think how the artificial intelligence can be applied at mobile devices. This article was the Introductory remarks of the Artificial Intelligence in Mobile Systems - AIMS2000 Workshop at 2000.
So , stay tuned! More content and tutorials about those topics will be presented here!

Regards,

Marcel Pinheiro Caraciolo

Mobile Recommender Systems


Hi Folks,

I am Marcel Pinheiro Caraciolo , the main author of this blog!

One of my goals at my master degree thesis is to study and apply artificial intelligence and data mining algorithms into mobile computing, solving problems or turning possible those machine learning algorithms run into small and limited processing devices like cell phones. I've already talked about this topic here.

I'm studying now about recommendation system engines and my plan is to develop a system based on machine learning techniques , data mining to offer specific products and services for mobile users that buys using the mobile phone. Based on mobile technology, the system will be possible to estimate by mobile payment the profile of a specific client and recommend products and services into the mobile device screen, with some profile analysis of the user behavior and consuming of products acquired using the mobile phone. We can resume the system features into 3 key points:

(a) Estimate the profile of clients and sellers to make recommendations of services and products.
(b) The automatic discovery of knowledge with induction of rules that explain the operational behavior on cellphones.

(c) The investigation of profiles on any characteristics in the mobile transactions (region, age, gender, consume, salary, habits, etc.)

During those months we will study a lot about data mining algorithms, mobile computing and recommender systems. Stay tuned!

Marcel Pinheiro Caraciolo

Data mining in practice: DataPreprocessing -The Use of Normalization

Monday, September 28, 2009



In this article, we will explore one of the basic steps in the knowledge discovery process, "Data Preprocessing", an important step that can be considered as a fundamental building block of data mining. The process of preprocessing has many steps, but can be summarized as the extraction, transformation and loading of the data. To be more precise modifying the source data into a different format which:

(a) enables data mining algorithms to be applied easily

(b) improves the effectiveness and the performance of the mining algorithms

(c) represents the data in easily and understandable format for both humans and machines

(d) supports faster data retrieval from databases

(e) makes the data suitable for a specific analysis to be performed.

The real world data can be considered extremely complicated to interpret without Data Preprocessing. I am going to explain this through a simple example based on Normalization. For people who come from database background this Normalization is completely different from 1st, 2nd and 3rd form of normalization used in the relational database design. We are talking about another type of normalization, and it's related to data preprocessing technique. To see how a simple data preprocessing technique could improve the effectiveness of analysis in orders of magnitude, let's move on further and talk about euclidian distance and how it's can be used to evaluate similarities between samples of data.

Euclidian Distance

Consider two points in a two-dimensional space (p1,p2) and (q1,q2) , the distance between these two points is given by the formula shown at the Figure 01.



Figure 01. Euclidean Distance Measure for 2-D Points


This is called the Euclidian Distance between two points. The same concept can be extended easily to multidimensional space. If the points are (p1,p2,p3,p4,...) and (q1,q2,q3,q4,...), the distance between the points is given by the formula (Figure 02).



Figure 02. Euclidean Distance for Multi-Dimensional Points


Now, I am going to introduce a sample data set of mobile profile users details. The task is to find the mobile users who have similar profiles, that is, that has similar use of the phone based on the call and SMS logs.

Table 01. Example Data Set (Mobile users profiles during one month)

In this data set, the first column is an unique identifier and the rest of the columns contain information. Ignoring the ID attribute, if we consider each column (attribute) as a dimension we can assume that each mobile user is represented by a point in 3-D space. The good thing is that we can calculate the distance between each of these points. The distance between points 1 and 2, (user 1 and 2) can be calculated as below:

Figure 03. Euclidean Distance between users 01 and 02.


Look at the data set above, through examination we figure out that the user id 1 and 4 are users with almost similar profiles, that is, use their phones very similar. So in the three dimensional space the distance between them should be less, that is, these two points should be very close.

The following table (Figure 04) gives the euclidean distance calculation for each user with the other users in our given data set.

Figure 04. Euclidean Distance Matrix for all users

We can see from the above list that the distance between the user 1 and 4 is 2000.00, which is less when compared between userId 1 and other users. So our interpretation seems to be correct. However, an alert reader would have noticed a significant observation here. If you see the list again, you can see that the euclidian distance values are very close to the differences in duration calls. Which this means ?

See this, the difference between the duration calls of users 1 and 4 is abs(25000 - 27000) = 2000, and the euclidean distance between one and four is 2000.30303! So it looks like this approach seems to be flawed. The euclidean distances are dominated by the duration calls amount. So guess you can't rely on euclidean distance to find mobile users with similar profile.

How do we get ourselves out of this problem ? We do not want the duration calls attribute to dominate the euclidean distance calculation. We can achieve this by applying one of the Data Preprocessing techniques called Normalization over the data set.

What is Normalization ?
The attribute data is scaled to fit into a specific range. There are many types of normalization available, we will see one technique called Min-Max Normalization. Min-Max Normalization transforms a value A to B which fits in the range [C,D]. It is given by the formula below (Figure 05):


Figure 05. Min-Max Normalization Formula

Consider the example below, the duration calls value is 50000, we want to transform this in to the range [0.0 , 1.0], so first we find the maximum value of duration calls which is 55000 and the minimum value of duration calls, 25000, them the new scaled value for 50000 will be:


Figure 06. Min-Max for Duration Calls Attribute from the User 01

Now let's apply the normalization technique to all the three attributes in our data set. Consider the following maximum and minimum values:

Max duration calls = 55001
Min duration calls = 24999
Min SMS = 23
Max SMS = 33
Max consume data = 8
Min consume data = 3

The attributes need to be scaled to fit in the range [0.0 , 1.0]. Applying the min-max normalization formula above, we get the normalized data set as given below (Figure 07):

Figure 07. Data set after Normalization


Now given the new data set all normalized, We will calculate the euclidean distances for each employee with the other employees. It's given in the table below (Figure 08):


Figure 08. Euclidean Distance Matrix for the data set

Now compare the euclidean distance calculation before and after normalization. We can see that the distances are no more dominated by the duration calls attribute and they make more sense now. The number of messages and data consumed now also contribute to the distance calculation. You can see how the normalization technique and data preprocessing can really help get useful and right information about your data before applying some machine learning or data mining algorithm.

To conclude this tutorial, it's important to notice that there are many measures similar to euclidean distance which can be used to calculate the similarity between two records such as Pearson coefficient, Tanimoto Coefficient, etc. You can try replacing euclidean distance with any of these measures and experiment.

You can read more on these measures in the following link. Take a special look at other normalization techniques such as Xˆ2 (X Square) Normalization and decimal scaling which are also worth trying.

Special thanks to the Blog IntelligenceMining that inspired me to write about this important topic!

Any doubts or suggestions,

Please make yourself welcome to give!

Marcel Pinheiro Caraciolo