2017년 3월 27일 월요일

[python] pandas subplot

fig, axes = plt.subplots(nrows=2, ncols=2)
fig.set_figheight(6)
fig.set_figwidth(8)
df[0].plot(ax=axes[0,0], style='r', label='Series'); axes[0,0].set_title(0)
df[1].plot(ax=axes[0,1]); axes[0,1].set_title(1)
df[2].plot(ax=axes[1,0]); axes[1,0].set_title(2)
df[3].plot(ax=axes[1,1]); axes[1,1].set_title(3)
fig.tight_layout()

2017년 3월 26일 일요일

[python] List Combine

import itertools

a = [ 1 , 1 ]
b = [ 2, 2 , 2]
c = [ 3 , 3 ]

result_A = a + b + c
result_B = list(itertools.chain(a,b,c))
a.extend(b)
a.extend(c)
result_C = a


print result_A
print result_B
print result_C

2017년 3월 20일 월요일

[python] flatten vs ravel

import numpy as np
y = np.array(((1,2,3),(4,5,6),(7,8,9)))
OUTPUT:
print(y.flatten())
[1   2   3   4   5   6   7   8   9]
print(y.ravel())
[1   2   3   4   5   6   7   8   9]


As explained here a key difference is that flatten is a method of an ndarray object and hence can only be called for true numpy arrays. In contrast ravel() is a library-level function and hence can be called on any object that can successfully be parsed. For example ravel() will work on a list of ndarrays, while flatten is not available for that type of object.

[algorithmn] 리스트의 순서를 바꾸지 않고, 각 값에 그 값의 크기에 할당된 크기의 값리스트 생성

[ 10 ,1 ,5 ] 시 [255 , 0 , 130 ] 의 리스트를 만드는것.

[1 , 10 ,5 ] 시 [0 , 255, 130] 이 된다.



1. [10, 1 ,  5] 의 크기순 set 을 만듬 => target_compare = [ 3, 1 , 2]

2. subset = [ 0 , 130 , 255] 만듬

3. result  = [ subset[i] for i in  target_compare  ]

2017년 3월 16일 목요일

[statistic] summery

- correlation
http://ezstat.snu.ac.kr/textbook_sources/chapter_05.pdf
https://en.wikipedia.org/wiki/Correlation_and_dependence

-

2017년 3월 15일 수요일

[python] Decorator

http://trowind.tistory.com/72
함수버전

def verbose(func):
print "Begin", func.__name__;
func();
print "End", func.__name__;

@verbose
def my_function():
print "hello, world."

my_functiont() 시

실제로는

verbose(my_function)

이 실행된다.


-----------------------
클래스버전

class Verbose:
def __init__(self, f):
print "Initializing Verbose."
self.tt = f;

def __call__(self):
print "Begin", self.tt.__name__
self.tt();
print "End", self.tt.__name__

@Verbose
def my_function():
    print "hello, world."


print "Program start"
my_function();


먼저 클래스의 __init__은 f라는 함수를 받는다.

그리고 __call__이란 부분이 데코레이터시 실행되는 부분이다 .

이건 실제로는

my_funtion() 을 실행시 Verbose.__call__(my_function) 이 실행된다.

즉 실제로는 아래와 같이 실행된다.

class Verbose:
def __init__(self, f):
print "Initializing Verbose."
self.tt = f;

def __call__(self):
print "Begin", self.tt.__name__
self.tt();
print "End", self.tt.__name__


def my_function():
    print "hello, world."

print "Program start"
ver = Verbose(my_function)
ver.__call__()

[kivy] object connection

1. kivy 파일 load로 연결

2. 한 kv 파일에서

으로 오브젝트를 만듬 -> 다른 kv 파일에서 이 오브젝트를 바로 사용 가능


    NAME:
        Line: ~~~



이걸 파이썬 코드에서 사용하고 싶으면, ID 부여, 그리고 접근을 어디서 할수 있게 할건지
정해야 한다.

이것은


    id: _NAME


    name_in_code : _NAME

이렇게 할시 , 파이썬 코드에서 NAME2 의 프로퍼티(어트리뷰트)중 name_in_code라는 프로퍼티가 생긴다. 이걸로 컨트롤을 할 수 있다.

[python] list slice index

data = [
    [1.0 , 1.0 , 4 , 10],
    [2.0 , 10.0, 4 , 10],
    [3.0 , 23.0, 4 , 10]
    ]

tempdata = [ item[2:] for item in data]

item[ 2 : ] mean from 2 to last

if want last - 1 element, just item [ 2 : -1 ]

2017년 3월 13일 월요일

[python] class member add

class tempclass():
    def __init__(self):
        self.member1 = 0


if __name__ == '__main__':
    te = tempclass()
    te.aa = 0
    te.yy = 'tt'

    print te.yy
    print te.aa


2017년 3월 7일 화요일

[kivy] Naming Rule

Kivy looks for a .kv file with the same name as your App class in lowercase
(minus “App” if it ends with ‘App’. eg. TutorialApp to tutorial.kv)

+ or tutorialApp.kv is also ok
Compared to Python syntax, Kivy syntax really sucks.

2017년 3월 6일 월요일

[python] tkinter - openfile dialog start with initial path

import Tkinter as tk
from tkFileDialog import askopenfilename

root = tk.Tk()
root.withdraw()
temp = askopenfilename(initialdir="c:\\")

2017년 3월 5일 일요일

[statistic] Confusion matrix


condition positive (P)
the number of real positive cases in the data
condition negatives (N)
the number of real negative cases in the data

true positive (TP)
eqv. with hit
true negative (TN)
eqv. with correct rejection
false positive (FP)
eqv. with false alarmType I error
false negative (FN)
eqv. with miss, Type II error




sensitivityrecallhit rate, or true positive rate (TPR)
specificity or true negative rate (TNR)


precision or positive predictive value (PPV)


negative predictive value (NPV)



accuracy (ACC)

장비의 분류 성능은 이정도만 제공해줘도 충분하다.






















[C#] Action and Func Chain

Action act1 = new Action( (x)=> Console.WriteLine("act1") );
            Action act2 = new Action( (x)=> Console.WriteLine("act2") );

            Action act3 = new Action((x) => { } );
            act3 += act1;
            act3 += act2;

            act3(1);
            Console.ReadLine();