Skip to content

Instantly share code, notes, and snippets.

View alfredplpl's full-sized avatar

Alfred Increment alfredplpl

View GitHub Profile
@alfredplpl
alfredplpl / randomForestImp.R
Last active December 23, 2015 03:49
How to use the variable important of Random forest.
library(randomForest)
#「フィッシャーのあやめ」データセットを読み出す
data(iris)
#データセットを特徴量とラベルに分割
features<-iris[1:4]
labels<-iris[5]
#ラベルを因子化
@alfredplpl
alfredplpl / randomForestImpResult.R
Last active December 23, 2015 03:49
Sample of variable importance.
setosa versicolor virginica MeanDecreaseAccuracy MeanDecreaseGini
Sepal.Length 7.277437 7.0994514 8.087167 10.842432 9.553025
Sepal.Width 5.029336 -0.4402422 2.381594 3.438372 2.528796
Petal.Length 22.909121 32.9889332 30.209000 35.201262 43.785432
Petal.Width 21.741775 30.5797963 31.309059 32.724397 43.400080
@alfredplpl
alfredplpl / BagOfFeatures.py
Last active May 12, 2021 03:19
This is a class of Bag-of-Features for OpenCV
import cv2
import numpy as np
class BagOfFeatures:
"""This is a class of Bag-of-Features by K-means for OpenCV"""
codebookSize=0
classifier=None
def __init__(self, codebookSize):
self.codebookSize=codebookSize
self.classifier=cv2.KNearest()
@alfredplpl
alfredplpl / BagOfFeaturesGMM.py
Last active December 25, 2015 02:19
This is a class of Bag-of-Features by GMM
#see also: http://scikit-learn.org/stable/modules/generated/sklearn.mixture.GMM.html
import numpy as np
from sklearn import mixture,preprocessing
class BagOfFeaturesGMM:
"""This is a class of Bag-of-Features by GMM """
codebookSize=0
classifier=None
def __init__(self, codebookSize):
@alfredplpl
alfredplpl / opencv_copyTo.cpp
Created October 16, 2013 13:37
OpenCV: paste a image
cv::Mat image=cv::imread("./image.png",-1);
cv::Rect rect(startColumn,startRow,image.cols,image.rows);
cv::Mat subdst=dst(rect);
image.copyTo(subdst);
cv::Mat image=cv::imread("./image.png",-1);
cv::Mat trans=cv::imread("./trans.png",0);
cv::Rect rect1(startColumn1,startRow1,trans.cols,trans.rows);
cv::Mat subdst1=dst(rect1);
trans.convertTo(subdst1,subdst1.type(),alpha);//double alphaは透過率[0.0, 1.0]
cv::Rect rect2(startColumn2,startRow2,image.cols,image.rows);
cv::Mat subdst2=dst(rect2);
image.copyTo(subdst2);
cv::Mat image=cv::imread("./image.png",-1);
cv::Mat image_mask=cv::imread("./mask.png",0);
cv::Rect rect(startColumn,startRow,image.cols,image.rows);
cv::Mat subdst=dst(rect);
image.copyTo(subdst,image_mask);
@alfredplpl
alfredplpl / bofTest.py
Created October 17, 2013 08:04
Test for BagOfFeatures.py
# -*- coding: utf-8 -*-
#BoF(SIFT)により一般物体認識を行うサンプルコード
#今回はイルカと象を識別
#評価用のデータセットとしてCaltech 101を使用
#see also: http://www.vision.caltech.edu/Image_Datasets/Caltech101/
import cv2
import numpy as np
from sklearn import svm
from sklearn import cross_validation
@alfredplpl
alfredplpl / resultBofTest.py
Created October 17, 2013 08:08
The result of bofTest.py
Ave. score(BagOfFeatures):70.492308[%]
Ave. score(BagOfFeaturesGMM):71.323077[%]
@alfredplpl
alfredplpl / hashLikeList.R
Created October 27, 2013 01:43
Its behavior is like hash (associative array).
#Its behavior is like hash (associative array).
hash.test=list("square"=function(x){x**2},
"pi"=3.1415926535)
hash.test[["square"]](2)
hash.test[["pi"]]
#probability that a random selected number is a prime number.
6/hash.test[["square"]](hash.test[["pi"]])