This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-coding:utf-8 -*- | |
""" | |
Neste primeiro dojo, vamos tentar resolver um problema bem simples com o | |
objetivo de ter um primeiro contato com as bibliotecas Numpy e Scipy. | |
Problema: Dada uma matriz de dimensão qualquer, encontrar o elemento de | |
valor máximo e o elemento de valor mínimo. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-coding:utf-8 -*- | |
""" | |
Neste primeiro dojo, vamos tentar resolver um problema bem simples com o | |
objetivo de ter um primeiro contato com as bibliotecas Numpy e Scipy. | |
Problema: Dada uma matriz de dimensão qualquer, encontrar o elemento de | |
valor máximo e o elemento de valor mínimo. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#-*-coding:utf-8 -*- | |
""" | |
Neste primeiro dojo, vamos tentar resolver um problema bem simples com o | |
objetivo de ter um primeiro contato com as bibliotecas Numpy e Scipy. | |
Problema: Dada uma matriz de dimensão qualquer, encontrar o elemento de | |
valor máximo e o elemento de valor mínimo. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
import urllib | |
API_KEY = "7084a6cb5d680c54df55fb3401ba042bfe9e5d55f61b65f0d8f027e0a0f486b2" | |
IP = '187.41.231.167' | |
url = "http://api.ipinfodb.com/v3/ip-city/?key=%s&ip=%s&format=json" % (API_KEY, IP) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from scipy import linalg | |
import numpy as np | |
from scipy.spatial.distance import cosine | |
#Let's define the matrix | |
user_ids = np.array(['Amanda', 'Anna', 'Bruno', 'Ricardo']) | |
item_ids = np.array(['Back to The Future', 'Conan', | |
'Lord of the Rings', 'Star Wars']) | |
matrix = np.matrix([ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def spearman_coefficient(X, Y): | |
""" | |
Considering the rows of X (and Y=X) as vectors, compute the | |
distance matrix between each pair of vectors. | |
Like Pearson Coefficient , but compares relative ranking of preference | |
values instead of preference values themselves. That is, each user's | |
preferences are sorted and then assign a rank as their preference value, | |
with 1 being assigned to the least preferred item. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
import sys | |
import random | |
def _rank_dists(ranks1, ranks2): | |
"""Finds the difference between the values in ranks1 and ranks2 for keys | |
present in both dicts. If the arguments are not dicts, they are converted | |
from (key, rank) sequences. | |
""" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# BM25F Model | |
def bm25(idf, tf, fl, avgfl, B, K1): | |
# idf - inverse document frequency | |
# tf - term frequency in the current document | |
# fl - field length in the current document | |
# avgfl - average field length across documents in collection | |
# B, K1 - free paramters | |
return idf * ((tf * (K1 + 1)) / (tf + K1 * (1 - B + B * (fl / avgfl)))) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# setup.py | |
from distutils.core import setup | |
from distutils.extension import Extension | |
from Cython.Distutils import build_ext | |
# for notes on compiler flags see: | |
# http://docs.python.org/install/index.html | |
setup( | |
cmdclass = {’build_ext’: build_ext}, | |
ext_modules = [Extension("calculate_z", ["calculate_z.pyx"])] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int fatorial(int n){ | |
if (n == 1) { | |
return 1; | |
} |