Skip to content

Instantly share code, notes, and snippets.

@supachaic
supachaic / vote.py
Created September 9, 2017 05:15
ensemble vote
from sklearn.ensemble import RandomForestClassifier
from sklearn.ensemble import AdaBoostClassifier
from sklearn.ensemble import ExtraTreesClassifier, VotingClassifier
from xgboost import XGBClassifier
rfo = RandomForestClassifier()
ada = AdaBoostClassifier()
ext = ExtraTreesClassifier()
xgb = XGBClassifier()
@supachaic
supachaic / randomsearch.py
Created September 9, 2017 05:20
RandomSearch with XGBClassifier
import scipy.stats as st
from sklearn.model_selection import RandomizedSearchCV
from xgboost import XGBClassifier
# Preconfigure estimator and parameters
estimator = XGBClassifier(nthreads=-1)
params = {
"n_estimators": st.randint(3, 40),
"max_depth": st.randint(3, 40),
"learning_rate": st.uniform(0.05, 0.4),
def vote(estimators, threshold, X_train, y_train, X_val, y_val, X_test, score_name):
predict_list = []
estimator_list = []
for estimator_name in estimators:
try:
params, val_score, timestamp = get_params(estimator_name)
if val_score > threshold:
print('Ensemble add %s' % estimator_name)
@supachaic
supachaic / combi.py
Created September 9, 2017 06:35
Search Combination and Vote
def all_subs(idx_list):
if idx_list == []:
return [[]]
indices = all_subs(idx_list[1:])
return indices + [[idx_list[0]] + i for i in indices]
def search_combination(predict_list, y_val, score_name):
idx_list = list(range(len(predict_list)))
@supachaic
supachaic / App.js
Last active December 28, 2018 02:34
Facial Recognition SPA
import React, { Component } from 'react';
import { Route, Router } from 'react-router-dom';
import createHistory from 'history/createBrowserHistory';
import './App.css';
import Home from './views/Home';
class App extends Component {
render() {
return (
@supachaic
supachaic / Home.js
Last active January 8, 2019 04:40
src/views/Home.js
import React, { Component } from 'react';
import { Link } from 'react-router-dom';
export default class Home extends Component {
render() {
return (
<div>
<h2>BNK48 Facial Recognition App</h2>
<li>
<Link to="/photo">Photo Input</Link>
@supachaic
supachaic / face.js
Last active March 9, 2019 04:16
src/api/face.js
import * as faceapi from 'face-api.js';
// Load models and weights
export async function loadModels() {
const MODEL_URL = process.env.PUBLIC_URL + '/models';
await faceapi.loadTinyFaceDetectorModel(MODEL_URL);
await faceapi.loadFaceLandmarkTinyModel(MODEL_URL);
await faceapi.loadFaceRecognitionModel(MODEL_URL);
}
@supachaic
supachaic / ImageInput.js
Last active January 6, 2019 07:04
src/views/ImageInput.js
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { loadModels, getFullFaceDescription } from '../api/face';
// Import image to test API
const testImg = require('../img/test.jpg');
// Initial State
const INIT_STATE = {
imageURL: testImg,
@supachaic
supachaic / App.js
Created January 4, 2019 08:53
Import ImageInput component and create new Route
import React, { Component } from 'react';
import { Route, Router } from 'react-router-dom';
import createHistory from 'history/createBrowserHistory';
import './App.css';
import Home from './views/Home';
import ImageInput from './views/ImageInput';
class App extends Component {
render() {
@supachaic
supachaic / ImageInput.js
Last active January 6, 2019 08:29
Draw face detection box
import React, { Component } from 'react';
import { withRouter } from 'react-router-dom';
import { loadModels, getFullFaceDescription } from '../api/face';
// Import image to test API
const testImg = require('../img/test.jpg');
// Initial State
const INIT_STATE = {
imageURL: testImg,