Skip to content

Instantly share code, notes, and snippets.

View joaopcanario's full-sized avatar
:octocat:
Hello World! =]

João Paulo Canário joaopcanario

:octocat:
Hello World! =]
View GitHub Profile
@joaopcanario
joaopcanario / GIF-Screencast-OSX.md
Created March 14, 2018 04:44 — forked from dergachev/GIF-Screencast-OSX.md
OS X Screencast to animated GIF

OS X Screencast to animated GIF

This gist shows how to create a GIF screencast using only free OS X tools: QuickTime, ffmpeg, and gifsicle.

Screencapture GIF

Instructions

To capture the video (filesize: 19MB), using the free "QuickTime Player" application:

@joaopcanario
joaopcanario / build_tf.sh
Created October 29, 2017 20:10 — forked from venik/build_tf.sh
Bash script for local building TensorFlow on Mac with all CPU optimizations (default pip package has only SSE)
#!/bin/bash
# Author: Sasha Nikiforov
# source of inspiration
# https://stackoverflow.com/questions/41293077/how-to-compile-tensorflow-with-sse4-2-and-avx-instructions
# check if VirtuelEnv activated
if [ -z "$VIRTUAL_ENV" ]; then
echo "VirtualEnv is not activated"
@joaopcanario
joaopcanario / knn.py
Last active March 8, 2020 15:13
[PT-BR] Implementação completa do algoritmo KNN. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Complete implementation of KNN Algorithm. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e
import math
import csv
import random
def load_dataset(path):
with open(path) as csvfile:
dataset = list(csv.reader(csvfile))
return dataset
@joaopcanario
joaopcanario / knn-6.py
Last active September 3, 2017 10:49
[PT-BR] Última parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Last part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mostre…
def evaluate(predictions, test_y):
for idx, prediction in enumerate(predictions):
print(f'> Predicted = {prediction}, Actual = {test_y[idx]}')
accuracy = sum(i == j for i, j in zip(
predictions, test_y)) / len(test_y) * 100.0
print(f'Model accuracy: {accuracy:.2f}%')
@joaopcanario
joaopcanario / knn-5.py
Last active September 3, 2017 10:50
[PT-BR] Quinta parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Fifth part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mostr…
def predict(train_y, k_neighbors):
knn_labels = [train_y[i] for i in k_neighbors]
return max(set(knn_labels), key=knn_labels.count)
@joaopcanario
joaopcanario / knn-4.py
Last active September 3, 2017 10:50
[PT-BR] Quarta parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Fourth part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/most…
def k_nearest_neighbors(train_set, test_instance, k=3):
distance = [euclidean_distance(X, test_instance) for X in train_set]
return sorted(range(len(distance)), key=lambda i: distance[i])[:k]
@joaopcanario
joaopcanario / knn-3.py
Last active September 3, 2017 10:50
[PT-BR] Terceira parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Third part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mos…
def euclidean_distance(point_p, point_q):
square_of_diffs = lambda p_i, q_i: (float(q_i) - float(p_i)) ** 2
distance = list(map(square_of_diffs, point_p, point_q))
return math.sqrt(sum(distance))
@joaopcanario
joaopcanario / knn-2.py
Last active September 3, 2017 10:51
[PT-BR] Segunda parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] Second part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mos…
def split_train_test(dataset, split_ratio=0.2):
dataset = random.sample(dataset, len(dataset))
test_ratio = int(len(dataset) * split_ratio)
train_ratio = len(dataset) - test_ratio
test_data = dataset[test_ratio:]
train_data = dataset[:train_ratio]
test_X = [data[:4] for data in test_data]
@joaopcanario
joaopcanario / knn-1.py
Last active September 3, 2017 10:51
[PT-BR] Primeira parte da minha implementação do algoritmo KNN do zero. O post onde eu explico o algoritmo está disponível em: https://medium.com/@joaopcanario/mostre-me-o-c%C3%B3digo-99398769113e [EN] First part of my implementation of KNN Algorithm from scratch. The post where I explain the algorithm is in: https://medium.com/@joaopcanario/mos…
import math
import csv
import random
def load_dataset(path):
with open(path) as csvfile:
dataset = list(csv.reader(csvfile))
return dataset
@joaopcanario
joaopcanario / Lista de exercicios.md
Last active June 16, 2017 21:45
Lista de exercícios que o Fernando Masanori (https://twitter.com/fmasanori) divulgou no grupo do Facebook `Python Brasil - Programadores` e que ele mandou para os alunos dele de introdução à programação no primeiro bimestre. É simples, pode ser um bom exercício para iniciantes (segundo ele é uma provinha para passar no Google Developer Day) e po…

EP2 – JOGO DA FORCA VERSÃO 2017-1 FATEC (diferente 2016)

(Prazo: 30 de junho. Não deixe de fazer as listas, caem na P2!) (pode ser feito em dupla, não necessariamente a do Big Brother)

Aviso: sempre visando o aprendizado do aluno este EP é da dupla, portanto não é tolerado o plágio. Caso você queira trocar alguma ideia com um colega, faça isso apenas verbalmente e de forma genérica, sem troca de código. Certifique-se de construir o seu EP desde o zero, pois programar modificando algum código pronto, de colegas ou achado na internet, configura plágio e assim você não irá aprender, que é o que realmente importa no curso. Alguns sites serão utilizados para verificação automática, se um código foi feito a partir de alterações de outro código.