Skip to content

Instantly share code, notes, and snippets.

View marcelcaraciolo's full-sized avatar
💭
Coding !

Marcel Caraciolo marcelcaraciolo

💭
Coding !
View GitHub Profile
@marcelcaraciolo
marcelcaraciolo / gist:1479727
Created December 15, 2011 03:40
RS Formal Definition
The problem involved in Recommender Systems is that of estimating the evaluations of items
unknown to an user and using these evaluations to recommend to the user a list of items
better evaluated, that is, those items which will more probably be of the user's interest.
To make such estimates, one may use the evaluations of other items made by the same user
or the evaluations made by the other users with similar interests to a particular user.
Formalizing the problem, given a set of users U and set of items I, let s be an utility
function which defines the punctuation (evaluation or note) of an item i for an user u.
That is: s: U x I -> P, in which P is a completely ordered set, formed by non-negative
values with an interval, 0 to 10, for example. The system must recommend an item i' which
@marcelcaraciolo
marcelcaraciolo / Apriori_rules.py
Created December 4, 2011 18:04
apriori_rules.py
def generateRules(L, support_data, min_confidence=0.7):
"""Create the association rules
L: list of frequent item sets
support_data: support data for those itemsets
min_confidence: minimum confidence threshold
"""
rules = []
for i in range(1, len(L)):
for freqSet in L[i]:
d = {192: u'A', 193: u'A', 194: u'A', 195: u'A', 196: u'A', 197: u'A',
199: u'C', 200: u'E', 201: u'E', 202: u'E', 203: u'E', 204: u'I',
205: u'I', 206: u'I', 207: u'I', 209: u'N', 210: u'O', 211: u'O',
212: u'O', 213: u'O', 214: u'O', 216: u'O', 217: u'U', 218: u'U',
219: u'U', 220: u'U', 221: u'Y', 224: u'a', 225: u'a', 226: u'a',
227: u'a', 228: u'a', 229: u'a', 231: u'c', 232: u'e', 233: u'e',
234: u'e', 235: u'e', 236: u'i', 237: u'i', 238: u'i', 239: u'i',
241: u'n', 242: u'o', 243: u'o', 244: u'o', 245: u'o', 246: u'o',
248: u'o', 249: u'u', 250: u'u', 251: u'u', 252: u'u', 253: u'y',
255: u'y'}
#-*- coding:utf-8 - *-
def load_dataset():
"Load the sample dataset."
return [[1, 3, 4], [2, 3, 5], [1, 2, 3, 5], [2, 5]]
def createC1(dataset):
"Create a list of candidate item sets of size one."
@marcelcaraciolo
marcelcaraciolo / decision_boundary.py
Created November 15, 2011 01:42
decision_boundary.py
#Plot Boundary
u = linspace(-1, 1.5, 50)
v = linspace(-1, 1.5, 50)
z = zeros(shape=(len(u), len(v)))
for i in range(len(u)):
for j in range(len(v)):
z[i, j] = (map_feature(array(u[i]), array(v[j])).dot(array(theta)))
z = z.T
contour(u, v, z)
@marcelcaraciolo
marcelcaraciolo / logistic_reg.py
Created November 15, 2011 01:39
logistic_reg.py
from numpy import loadtxt, where, zeros, e, array, log, ones, append, linspace
from pylab import scatter, show, legend, xlabel, ylabel, contour, title
from scipy.optimize import fmin_bfgs
def sigmoid(X):
'''Compute the sigmoid function '''
#d = zeros(shape=(X.shape))
den = 1.0 + e ** (-1.0 * X)
@marcelcaraciolo
marcelcaraciolo / log_regression.py
Last active August 7, 2019 18:51
Logistic prediction
def sigmoid(X):
'''Compute the sigmoid function '''
#d = zeros(shape=(X.shape))
den = 1.0 + e ** (-1.0 * X)
d = 1.0 / den
return d
@marcelcaraciolo
marcelcaraciolo / mapfeature.py
Created November 15, 2011 00:36
Map Feature
def map_feature(x1, x2):
'''
Maps the two input features to quadratic features.
Returns a new feature array with more features, comprising of
X1, X2, X1 ** 2, X2 ** 2, X1*X2, X1*X2 ** 2, etc...
Inputs X1, X2 must be the same size
'''
x1.shape = (x1.size, 1)
@marcelcaraciolo
marcelcaraciolo / prediction.py
Created November 13, 2011 12:54
Logistic prediction
def predict(theta, X):
'''Predict whether the label
is 0 or 1 using learned logistic
regression parameters '''
m, n = X.shape
p = zeros(shape=(m, 1))
h = sigmoid(X.dot(theta.T))
for it in range(0, h.shape[0]):
list_to_search = [1,4,1,4,6,5,5,5,4,2,3]
elements_to_find = [1,3,5]
search_list = lambda l,e : [ [ idx for idx, element in enumerate(l) if element == element_f ] for element_f in e]
search_list(list_to_search, elements_to_find)