기본 콘텐츠로 건너뛰기

라벨이 regression인 게시물 표시

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

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은 열단위 즉, 행 방향으

softmax 모델(Softmax Regression)

내용 Softmax 회귀 모델 비용함수 모델 생성 Softmax Regression Softmax 회귀 모델 데이터를 두 개의 클래스로 구분하기 위한 예측 방법인 로지스틱 회귀는 2개 이상의 클래스로 분류하기 위해 softmax 방법으로 일반화 할 수 있습니다. 이 방법을 softmax 회귀 또는 다중 로지스틱 회귀 (multinomial Losgistic regression)이라고 합니다. 이 모델은 우선적으로 각 인스턴스에 대해 식 1을 적용합니다. 이것은 그 인스턴스의 각 클래스에 대한 점수를 나타냅니다. 다음으로 식 2의 softmax 함수를 사용하여 각 클래스에 포함될 확률을 추정합니다. $$\begin{equation}\tag{1}s_k(x)=x^T\theta^{(k)}\end{equation}$$ 각 클래스 k는 자신의 가중치벡터 θ (k) 를 가집니다. 예를 들어 3개의 특성(독립변수)과 3개의 클래스들(A, B, C)를 가진 라벨(반응변수)에 대해 다음과 같이 각 인스턴스(샘플)의 점수를 계산할 수 있습니다. $$\begin{align}&\text{- A or not}\\ &\begin{bmatrix} W_{A1} &W_{A2}&W_{A3} \end{bmatrix}\begin{bmatrix} x_1\\x_2\\x_3 \end{bmatrix} = \begin{bmatrix} W_{A1}x_1+W_{A2}x_2+W_{A3}x_3 \end{bmatrix}=s(x)_A \\ &\text{- B or not}\\ &\begin{bmatrix} W_{B1} &W_{B2}&W_{B3} \end{bmatrix} \begin{bmatrix} x_1\\x_2\\x_3 \end{bmatrix} = \begin{bmatrix} W_{B1}x_1+W_{B2}x_2+W_{B3}x_3 \end{bmatrix}=s(x)_B\\ &\text{-

로지스틱회귀(Logistic Regression)

내용 로지스틱회귀 비용함수 LogisticRegression() 결정경계 주가 자료에 적용 로지스틱회귀(Logistic Regression) 로지스틱회귀 로지스틱 회귀분석은 독립변수(특성, 설명변수)에 대해 반응변수(라벨)를 로짓변수 (logit variavble, 반응변수의 발생 확률의 자연로그)로 변환한 후 인스턴스(smaple)가 두 개의 클래스로 구분된 라벨(반응변수) 중에 특정한 클래스에 속하는 확률(최대우도)을 추정하기 위해 사용됩니다. 그러므로 이 회귀 모델은 binary classificatier를 구축하게 됩니다. 선형회귀와 유사하게 로지스틱회귀 역시 입력 변수들과 가중치들의 곱이 계산됩니다. 그러나 선형회귀의 경우 이 곱의 결과가 직접적으로 사용되는 것에 비해 로지스틱 회귀의 경우는 시그모이드 함수 (sigmoid function, σ(·))을 통해 [0, 1] 사이의 값으로 변환시킵니다. 즉, 식 1과 같은 연산에 의해 인스턴스의 결과(확률)가 계산됩니다. $$\begin{align}\tag{1} &\hat{p}=h_\beta(x)=\sigma\left(x^T\beta\right)\\ &t=x^T\beta\\ \tag{2}&\sigma(t)=\frac{1}{1+\exp(-t)}\end{align}$$ 시그모이드 함수(식 2)는 변수와 가중치의 곱의 결과를 0과 1사이의 값으로 변환합니다. import numpy as np import pandas as pd import matplotlib.pyplot as plt import FinanceDataReader as fdr from mpl_toolkits.mplot3d import Axes3D font1={'size':11, 'weight':'bold'} def sigmoid(x): return 1/(1+np.exp(-x)) t=np.linsp

Multiple Perception Lyers: Regression

Multiple Perception Lyers: Regression tensorflow.keras를 적용하여 kospi 주가의 회귀모형을 구축합니다. > colab 에서 실행한 코드로 주식자료를 호출하기 위해 다음 패키지 설치가 필요합니다. !pip install -U finance-datareader import numpy as np import pandas as pd import matplotlib.pyplot as plt from sklearn.preprocessing import StandardScaler from sklearn import metrics from sklearn.model_selection import train_test_split from sklearn.model_selection import KFold import tensorflow as tf from tensorflow.keras import models, layers import FinanceDataReader as fdr 주가 데이터의 이동평균을 계산하고 원시데이터에 연결하기 위한 함수를 작성합니다. #이동평균을 원시데이터에 연결 def addMa(data, window=[3,5]): for i in window: y=data.rolling(i).mean() y.columns=[f"{j}_{i}" for j in y.columns] data=pd.concat([data, y], axis=1).dropna() return(data) def maDataMake(da, window=[3, 5]): x=addMa(da, window) x1=x.replace(0, method='ffill') x1=x1.replace(np.inf, method='ffill') x1=x1.dropna() return(x1) 주가 자료를 호출합니다. st=pd.Ti

Autocorrelation & Mean of Square Error

Contents Autocorrelation analysis Mean of Square Error Residual(Error) The generated regression model needs to be statistically tested, and the main object in the test is an error, the difference between the observations and estimates calculated by Equation 1. $$\begin{align}\tag{1}\text{e}&=y-(b_0+b_1x)\\&=y-\hat{y} \end{align}$$ Errors in the regression model have the following prerequisites: Probability variables that follow a normal distribution Because independent variables are probabilities that follow a normal distribution, the error between the response and the estimate is also a probability variable that follows a normal distribution. This means that the error cannot be artificially adjusted. Homoscedastic of error terms Various regression models are possible, as shown in Figure 1. This means that you can configure the probability distribution for the regression coefficients. This distribution has means and variances. The mean of this distrib

Regression Analysis: simple regression & regression coefficient

Contents What is Regression? Simple regression Regression Coefficient What is Regression? Regression is a statistical method of setting up a model for the relationship between variables and estimating new values through that model. Figure 1 is a graph of the force (y) corresponding to a constant height (x), showing the exact direct proportional relationship in which y increases as x increases. This relationship is based on data from generalized laws of physics, which can fully predict the forces applied at a certain height within the Earth where gravity acts. plt.figure(figsize=(7,5)) h=range(7) w=40 F=[w*9.8*i for i in h] plt.plot(h, F, "o-") plt.xlabel("Height(m)", size=13, weight="bold") plt.ylabel("Force(N)", size=13, weight="bold") plt.text(2.5, 1500, 'F=Wgh', color="blue", size=13, weight="bold") plt.text(2, -600, r'w:weight (kg), g: Gravity Acceleration($m/sec^2$)', color="

선형신경망_linear Regression

목차 선형신경망 Minibatch Stocastic Gradient Descent 정규분포와 제곱손실 Minibatch의 생성 모델 생성 high-level APIs of deep learning frameworks 선형신경망 회귀분석은 하나이상의 독립변수와 종속변수 사이의 관계를 모형화는 일련의 방법입니다. 예측, 분류와 관계된 경우에 사용합니다. 예로 가격 예측(주택, 주식 등), 입원 기간 예측(병원 환자의 경우), 수요 예측(소매 판매) 등을 생각할 수 있습니다. 선형회귀의 경우 다음을 가정합니다. 독립 변수 x와 종속 변수 y 사이의 관계가 선형이라고 가정합니다. 즉, 관측치에 대한 약간의 노이즈가 주어졌을 때 y는 x에 있는 요소의 가중 합으로 표현될 수 있다. 이 모델에서 파생되는 노이즈는 정규분포에 부합한다고 가정합니다. 가격, 면적, 연령으로 구성된 자료에서 가격을 예측하기 위한 선형모델을 구축한다고 할 때 그 데이터 셋은 다음과 같은 모양일 것입니다. 면적 연령 가격 - - - $\vdots$ $\vdots$ $\vdots$ 위 데이터 구조에서 각 행을 예제(데이터 포인트, 데이터 인스턴스, 샘플)이라 합니다. 예측하고자 하는 것을 레벨(타겟)이라 합니다. 에측의 기반이 되는 독립변수를 특성(feature) 또는 공변량(covariate)라고 합니다. 데이터셋의 전체 수(행의수)를 n, 데이터 인스턴스(예제)를 i로 표현합니다. 그러므로 입력변수 X와 y는 다음과 같습니다. $$X^{(i)}=[x^{(i)}_1, x^{(i)}_2]^T, y^{(i)}$$ $$\begin{align}\tag{1}&\text{price}=w_{area} \cdot \text{area}+w_{age} \cdot \text{age}+b\\ &a