본문 바로가기

데이터 과학/데이터 과학

np.percentile 사용법 numpy.percentile(v, q) 은 q번째 퍼센트의 데이터를 계산한다. 다시 말해 백분위 q에 위치한 값을 계산한다. 길이가 n이 벡터 v가 주어지면, v의 q번째 백분위 수는 v의 정렬된 복사본에서 최소값 ~ 최대값 q/100 이다. 정규화된 순위가 q의 위치와 정확히 일치하지 않는다면, 두개의 가장 가까운 이웃 값과의 거리가 백분위 값이 된다. a = np.array([[10, 7, 4], [3, 2, 1]]) >>> a array([[10, 7, 4], [ 3, 2, 1]]) >>> np.percentile(a, 50) 3.5 >>> np.percentile(a, 50, axis=0) array([6.5, 4.5, 2.5]) >>> np.percentile(a, 50, axis=1) arr.. 더보기
Json 파일 읽어 들이는 2가지 방법 파일로 된 Json 데이터를 읽어 들이는 (본인이 알고 있는) 두가지 방법을 정리한다. 1. Json 관련 라이브러리를 이용하는 방법 - https://json-c.github.io/json-c/ - 사용 방법은 다른 포스트에 정리해 놓았다. 2. 파일 스트림을 이용하는 방법 - (1) fstream을 이용해서 파일을 스트림으로 바꾼다. - (2) 파일 스트림을 json 유틸을 이용해서 읽어온다(본인의 경우 사용자가 많은 rapidJson을 이용하였다) #include #include #include #include "rapidjson/document.h" int main() { std::ifstream fIn("test.json"); std::string str; if (in.is_open()) { f.. 더보기
KL Divergence(Kullback Leibler Divergence) 설명 출처) https://www.countbayesie.com/blog/2017/5/9/kullback-leibler-divergence-explained Kullback-Leibler Divergence Explained — Count Bayesie Kullback–Leibler divergence is a very useful way to measure the difference between two probability distributions. In this post we'll go over a simple example to help you better grasp this interesting tool from information theory. www.countbayesie.com (번역) 해당 .. 더보기
Density Estimation (in Python) ※ scikit-learn.org/stable/modules/density.html 2.8. Density Estimation — scikit-learn 0.24.1 documentation 2.8. Density Estimation Density estimation walks the line between unsupervised learning, feature engineering, and data modeling. Some of the most popular and useful density estimation techniques are mixture models such as Gaussian Mixtures (GaussianMixture scikit-learn.org 아래 글은 본 링크 글을 번역한.. 더보기
[MIT] 데이터 사이언스 기초 강의 요약[11 ~ 15강] Chapter 11. Introduction to Machine Learning ▶지도 학습(Supervised Learning) - 분류(Classification), 회귀(Regression)가 존재 - 분류 : 라벨을 예측하는 것(이중 분류 or 다중 분류) (e.g. K-NN) - 회귀 : 연속적인 숫자 혹은 부동소수점을 예측하는 것 (e.g. Linear or Polynomial Regression) ※ 회귀는 분류와 다르게 출력 값에 연속성이 있다. ▶비지도 학습(Unsupervised Learning) - 원래 데이터를 보다 쉽게 해석할 수 있도록 만드는 알고리즘 - 비지도 변환(Unsupervised Transformation), 군집(Clustering), 이상 탐지(Anomaly Det.. 더보기
JSON (JavaScript Object Notation) in C Json 파일 읽어 들이기 //Allocation struct json_object* json_object_from_file(const char* filename) //e.g. struct json_object *pJsonroot = NULL; pJsonroot = json_object_from_file(pPath); //Free json_object_put(pJsonroot); 파일 경로(string)참고하여 json 읽어 들이고 json_object 포인터 반환. 이후 json_object_put을 이용해 해제 해줘야 한다. Json 파일 파싱하기 struct json_object* json_object_object_get(struct json_object* obj, const char* key) i.. 더보기
[MIT] 데이터 사이언스 기초 강의 요약[6 ~ 10강] Chapter 6. Monte Carlo Simulation ▶ 추리 통계학 모집단(Population) : 예시들의 집합, Set of Examples. 표본(Sample) : 모집단의 적당한 부분 집합, Subset of Population. 핵심 개념 : 랜덤 샘플(random sample)한 표본은 모집단과 동일한 특성을 갖는 경향이 있음 분산이 커질 수록 같은 수준의 신뢰도를 갖기 위해서는 더 큰 표본이 필요. ▶ 큰수의 법칙(베르누이의 법칙) 각 실행에서 특정 결과가 나올 실제 확률이 p로 독립인 사건(Independent tests with the same actual probability p)에서, 실행 횟수가 무한대로 갈수록 p와 다른 결과가 나오는 횟수의 비율이 0으로 수혐한다. ▶ 도.. 더보기
[MIT] 데이터 사이언스 기초 강의 요약[1 ~ 5강] Chapter 1, 2. Optimization Problems 탐욕 알고리즘 - 순간에 최적이라고 생각하는 것을 선택해 나간다. 장점 : 구현이 쉬움, 빠르다 단점 : 최적의 해가 아닐 수도 있다. Brute Force 알고리즘 - 항목 전체 조합을 나열하여 한계를 벗어나는 것은 제거. 동적 프로그래밍 - 복잡한 문제를 간단한 여러 개의 문제로 나누어 해결. - 동적 프로그래밍의 알고리즘인 'memoization'을 적용하려면 참조적 투명성(referential transparency)가 보장되어야 한다. ※ 참조적 투명성(referential transparency) : 입력이 같으면, 출력이 동일. 함수 반환값이 입력값 만으로 결정된다. def fastFib(n, memo = {}): """Assu.. 더보기