기본 콘텐츠로 건너뛰기

통계관련 함수와 메서드 사전

A B C d E F G H I K L M N O P Q R S T U V W Z A statsmodels.ap.stats.anova_lm(x) statsmodels.formula.api.ols 에 의해 생성되는 모형 즉, 클래스 인스턴스(x)를 인수로 받아 anova를 실행합니다. np.argsort(x, axis=-1, kind=None) 객체 x를 정렬할 경우 각 값에 대응하는 인덱스를 반환합니다. Axis는 기준 축을 지정하기 위한 매개변수로서 정렬의 방향을 조정할 수 있음(-1은 기본값으로 마지막 축) pandas.Series.autocorr(lag=1) lag에 전달한 지연수에 따른 값들 사이의 자기상관을 계산 B scipy.stats.bernoulli(x, p) 베르누이분포에 관련된 통계량을 계산하기 위한 클래스를 생성합니다. x: 랜덤변수 p: 단일 시행에서의 확률 scipy.stats.binom(x, n, p) 이항분포에 관련된 통계량을 계산하기 위한 클래스를 생성합니다. x: 랜덤변수 n: 총 시행횟수 p: 단일 시행에서의 확률 C scipy.stats.chi2.pdf(x, df, loc=0, scale=1) 카이제곱분포의 확률밀도함수를 계산 $$f(x, k) =\frac{1}{2^{\frac{k}{2}−1}Γ(\frac{k}{2})}x^{k−1}\exp\left(−\frac{x^2}{2}\right)$$ x: 확률변수 df: 자유도 pd.concat(objs, axis=0, join=’outer’, …) 두 개이상의 객체를 결합한 새로운 객체를 반환. objs: Series, DataFrame 객체. Axis=0은 행단위 즉, 열 방향으로 결합, Axis=1은 열단위 즉, 행 방향으

Type of Variable & ratio

Types of variables

All data generated by measurement, surveys, research, etc. can be variables and also use the term feature in machine learning. An event contains multiple variable values and is called an instance. The following table contains three variables: name, age, gender, height, and three events: instances. A typical form of data, each variable consists of a column and an instance of a row, which is called a dataset.


name age sex height
A 10 male 153
B 15 female 161
C 21 male 181

In constructing a dataset, the number of questions equals the number of variables, and the number of respondents affects the number of observations. However, the number of respondents does not affect the number of variables.
As shown in Table 1.1, all variables are separated by categorical variables and quantitative variables, and variables are separated by nominal, ordinal, discrete, and continuous, depending on the measurement level.


Types of variables
Variable Contents Level
Categorical variables Group(Class) Nominal
Ordinal
Quantitative variables Quantity(Size) Discrete
Continuous

Nominal variables are variables that can only be qualitative classified without logical order. For example, for a dataset of fruits, 1=apples, 2=folds, and 3=watermelons, each fruit is numbered 1, 2 and 3, but the fruit is logically irrelevant between rank and other values. You can only give a name.

Movies can be ranked using rating data that is given within a certain range. However, ratings are subjective evaluations and the intervals between each rating are not constant either. These variables are called ordinal variables.

For quantitative variables, measurement levels have their own ranks, and differences between them are measurable and interrelated. Also, the figure itself is meaningful. Therefore, for the same level, it has the same meaning. For these measurement levels, they are divided into countable variables and uncountable parts, respectively, called discrete and continuous. Discrete refers to a form that can be represented as an integer, such as a population belonging to a certain group, and continuous refers to a form of proportion to absolute criteria such as temperature, height, weight, etc.

Example 1)
  Determine the measurement level of the following variables:
  • Age: discrete, there is a clear measure of measurement, and the difference between ages is meaningful.
  • Party Name: Nominal, this variable can only classify names.
  • Weight: Continuous, absolute reference value 0 exists. You can generate figures proportionally based on zero, but you cannot represent them in clear numbers, such as natural numbers or integers.
  • If students are grouped into three groups A, B, and C, the variable 'group': nominal
  • If players A, B, and C are participating in steps 5, 2 and 3 respectively, then the variable "Step": ordinal. For this variable, the differences within or between steps are not necessarily equal.
  • The movie was evaluated on a 5-point scale such as very good, good,... The level of the variable in this outcome: ordinal, in this survey, ordinal number are important. However, the difference between those intervals is not equal.
  • City Name: Nominal. You can just give it a name, but you can't rank it.
  • People's bank balances: continuous. The difference between each value is the same, and the value itself has meaning.

ratio

Distinguish between absolute and relative proportions.

  • absolute proportion: part of a whole
  • Relative Ratio: Increase or decrease relative to another ratio

The reason for the news that a city is not safe with the increase in crime cases is probably the rate of increase. If this news is added with information about a 50% increase in the homicide rate, it gives the basis for the news that it will get worse, but it's still incomplete. Its incompleteness is due to the lack of information about the number of events being compared, such as an increase from 2 to 3 or an increase from 10 to 4. That is, an increase of 50% is for an increase over the number of past events. Previous figures are needed for complete information. In this case, 50% is a relative ratio, and information about the absolute ratio is needed to fully understand this news. For example, in a city with a population of 100,000 people, if 3 cases occurred compared to 2 cases in the previous year, the increase would be 50%, but an absolute increase of 0.2% to 0.3% would significantly weaken the basis of the negative news. As such, the meaning of relative and absolute ratios is very important, and reporting only relative ratios should be avoided.

The following shows the change in population density in Seoul and the neighboring metropolitan area, and unlike the above case, a clear trend is shown by the relative ratio.

Seoul neighboring
Year Density Relative ratio(%) Density Relative ratio(%)
2106 16263 - 25350 -
2017 16136 -0.78 25476 0.50
2018 16034-0.63 25675 0.78
2019 15964 -0.44 25844 0.66

댓글

이 블로그의 인기 게시물

matplotlib의 그래프 종류

1. 산포도(scatter plot) plt.scatter(x, y) >>> import matplotlib.pyplot as plt >>> import numpy as np >>> data=np.random.rand(1024, 2) >>> data[:3, :] >>> plt.scatter(data[:,0], data[:,1]) >>> plt.show() 2. 막대그래프(bar chart) plt.bar(x, hight, width, align='center') 매개변수중 width에 인수를 전달하여 막대의 두께를 조절할 수 있다. 또한 align의 인수는 'center'와 'edge' 이다. 기본값은 'center'이다. 이 값은 x축의 레이블이 막대의 중간에 위치(center) 또는 왼쪽 가장자리에 위치(edge)시킨다. 코드에서 np.random.randint 는 특정한 범위내에서 지정한 갯수의 랜덤수를 생성 np.unique(배열, retrun_counts=False, axis=None) : 객체 내의 중복되지 않은 수들을 반환한다. return_counts=True이면 각 수에 대한 빈도수를 반환한다. axis를 통해 행(1), 열(0)을 선택한다. >>> x=np.random.randint(1, 6, size=100) >>> uni,count=np.unique(x, return_counts=True) >>> uni array([1, 2, 3, 4, 5]) >>> count array([25, 17, 23, 16, 19], dtype=int64) >>> plt.bar(uni, count) >>> plt.show() 위의 막대그래프의 막대의

유사변환과 대각화

내용 유사변환 유사행렬의 특성 대각화(Diagonalization) 유사변환(Similarity transformation) 유사변환 n×n 차원의 정방 행렬 A, B 그리고 가역 행렬 P 사이에 식 1의 관계가 성립하면 행렬 A와 B는 유사하다고 하며 이 변환을 유사 변환 (similarity transformation)이라고 합니다. $$\begin{equation}\tag{1} A = PBP^{-1} \Leftrightarrow P^{-1}AP = B \end{equation}$$ 식 1의 유사 변환은 다음과 같이 고유값을 적용하여 특성 방정식 형태로 정리할 수 있습니다. $$\begin{align} B - \lambda I &= P^{-1}AP – \lambda P^{-1}P\\ &= P^{-1}(AP – \lambda P)\\ &= P^{-1}(A - \lambda I)P \end{align}$$ 위 식의 행렬식은 다음과 같이 정리됩니다. $$\begin{align} &\begin{aligned}\textsf{det}(B - \lambda I ) & = \textsf{det}(P^{-1}(AP – \lambda P))\\ &= \textsf{det}(P^{-1}) \textsf{det}((A – \lambda I)) \textsf{det}(P)\\ &= \textsf{det}(P^{-1}) \textsf{det}(P) \textsf{det}((A – \lambda I))\\ &= \textsf{det}(A – \lambda I)\end{aligned}\\ &\begin{aligned}\because \; \textsf{det}(P^{-1}) \textsf{det}(P) &= \textsf{det}(P^{-1}P)\\ &= \t

sympy.solvers로 방정식해 구하기

sympy.solvers로 방정식해 구하기 대수 방정식을 해를 계산하기 위해 다음 함수를 사용합니다. sympy.solvers.solve(f, *symbols, **flags) f=0, 즉 동차방정식에 대해 지정한 변수의 해를 계산 f : 식 또는 함수 symbols: 식의 해를 계산하기 위한 변수, 변수가 하나인 경우는 생략가능(자동으로 인식) flags: 계산 또는 결과의 방식을 지정하기 위한 인수들 dict=True: {x:3, y:1}같이 사전형식, 기본값 = False set=True :{(x,3),(y,1)}같이 집합형식, 기본값 = False ratioal=True : 실수를 유리수로 반환, 기본값 = False positive=True: 해들 중에 양수만을 반환, 기본값 = False 예 $x^2=1$의 해를 결정합니다. solve() 함수에 적용하기 위해서는 다음과 같이 식의 한쪽이 0이 되는 형태인 동차식으로 구성되어야 합니다. $$x^2-1=0$$ import numpy as np from sympy import * x = symbols('x') solve(x**2-1, x) [-1, 1] 위 식은 계산 과정은 다음과 같습니다. $$\begin{aligned}x^2-1=0 \rightarrow (x+1)(x-1)=0 \\ x=1 \; \text{or}\; -1\end{aligned}$$ 예 $x^4=1$의 해를 결정합니다. solve() 함수의 인수 set=True를 지정하였으므로 결과는 집합(set)형으로 반환됩니다. eq=x**4-1 solve(eq, set=True) ([x], {(-1,), (-I,), (1,), (I,)}) 위의 경우 I는 복소수입니다.즉 위 결과의 과정은 다음과 같습니다. $$x^4-1=(x^2+1)(x+1)(x-1)=0 \rightarrow x=\pm \sqrt{-1}, \; \pm 1=\pm i,\; \pm1$$ 실수