Skip to content

Instantly share code, notes, and snippets.

View WittmannF's full-sized avatar
🇧🇷

Fernando Marcos Wittmann WittmannF

🇧🇷
View GitHub Profile
@WittmannF
WittmannF / compare-svm-kernels.py
Last active July 5, 2024 15:02
Visualization of SVM Kernels Linear, RBF, Poly and Sigmoid on Python (Adapted from: http://scikit-learn.org/stable/auto_examples/classification/plot_classifier_comparison.html)
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import ListedColormap
from sklearn.cross_validation import train_test_split
from sklearn.preprocessing import StandardScaler
from sklearn.datasets import make_moons, make_circles, make_classification
from sklearn.svm import SVC
h = .02 # step size in the mesh
@WittmannF
WittmannF / example.py
Last active February 27, 2017 17:40
Example of code for achieving an accuracy higher than 83% at the P0 of MLND (adapted from the submission of one of the students)
if passenger['Sex'] == 'male':
# male
if passenger['Age'] < 10:
if passenger['Pclass'] == 3:
if passenger['SibSp'] > 1:
predictions.append(0)
else:
predictions.append(1)
else:
@WittmannF
WittmannF / TFLearnxSklearn.csv
Last active July 24, 2018 17:58
Table with some equivalents between Sklearn and TFLearn
Task Sklearn TFLearn
Train a classifier .fit(X) .fit(X)
Get the accuracy score .score(X, y) .evaluate(X, y)
Predict classes .predict(X) .predict_label(X)
@WittmannF
WittmannF / hello_tflearn.py
Created July 24, 2018 18:39
Hello TFLearn!
from sklearn.datasets import load_breast_cancer
from sklearn.model_selection import train_test_split
from tflearn.data_utils import to_categorical
import tflearn
## Load the dataset
X, y = load_breast_cancer(True)
## Train/Test Split and convert class vector to a binary class matrix
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.33, random_state=42)
import numpy as np
import cv2, os
face_cascade = cv2.CascadeClassifier('cascade/haarcascades/haarcascade_frontalface_alt2.xml')
cap = cv2.VideoCapture(0)
while(True):
# Capture frame-by-frame
ret, frame = cap.read()
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.5, minNeighbors=5)
for (x, y, w, h) in faces:
@WittmannF
WittmannF / reconhecimento-facial-autoxml.py
Last active June 6, 2020 15:07
Reconhecimento facial em python com busca automática do arquivo XML
import cv2, os
# Funcao para busca de arquivos
def find(name, path):
for root, dirs, files in os.walk(path):
if (name in files) or (name in dirs):
print("O diretorio/arquivo {} encontra-se em: {}".format(name, root))
return os.path.join(root, name)
# Caso nao encontre, recursao para diretorios anteriores
return find(name, os.path.dirname(path))
import cv2, os
BLUE_COLOR = (255, 0, 0)
STROKE = 2
xml_path = 'haarcascade_frontalface_alt2.xml'
clf = cv2.CascadeClassifier(xml_path)
cap = cv2.VideoCapture(0)
while(not cv2.waitKey(20) & 0xFF == ord('q')):
print(__doc__)
# Code source: Gaël Varoquaux
# Andreas Müller
# Modified for documentation by Jaques Grobler
# License: BSD 3 clause
import numpy as np
import matplotlib.pyplot as plt
@WittmannF
WittmannF / whatsapp_api.py
Created November 14, 2018 21:34
WhatsApp API Selenium
"""
### Implemented Methods
- Get contacts from a selected group
### Requires
- Selenium: `pip install selenium`
- ChromeDriver: http://chromedriver.chromium.org/
- After downloading chromedriver, make sure to add in a folder accessible from the PATH
### Example of Usage:
@WittmannF
WittmannF / exemplo_bizelli.py
Last active November 21, 2018 22:07
Rename subtitles from Udacity class. Code by Bizelli.
import os
def rename_dir(path,sufix,extension_searched):
for file_name in os.listdir(path):
file_name_without_ext = os.path.splitext(file_name)[0]
extension = os.path.splitext(file_name)[1]
if extension == extension_searched:
if file_name_without_ext.rfind(sufix) > 0:
new_file_name = file_name[:file_name_without_ext.rfind(sufix)] + extension_searched
os.rename(os.path.join(path,file_name),os.path.join(path,new_file_name))