AI

Non-Linear Regression 실습

Beomsu Koh 2023. 7. 6.

Non-Linear Regression 실습

- 데이터를 보고, 그래프를 그릴 식을 추정해야 한다.
- pd/np -> plt(mataplotlib) 순으로 라이브러리를 사용한다
  • 목표
    • Differentiate between linear and non-linear regression
    • Use non-linear regression model in Python

Intro. Non-Linear Regression 왜 쓰냐?

비선형 회귀는 독립 변수 x와 종속 변수 y 사이의 비선형 관계를 모델링하는 방법입니다.
일반적으로 선형이 아닌 모든 관계를 비선형 관계로 간주할 수 있으며, 이는 주로 다항식의 형태로 표현됩니다.

다항식의 최고 차수는 k입니다 (x의 최고 차수).

비선형 함수에는 지수, 로그, 분수 등의 요소가 포함될 수 있습니다.

로그 함수와 같은 더 복잡한 함수도 가능합니다:

이러한 비선형 함수를 사용하여 데이터를 모델링하고 예측함으로써 데이터의 복잡성과 다양성을 더 잘 포착할 수 있습니다.

비선형 회귀를 사용하여 실제 현상을 더 정확하게 모델링하고 예측할 수 있습니다.

예제

x = np.arange(-5.0, 5.0, 0.1)

##You can adjust the slope and intercept to verify the changes in the graph
y = 1*(x**3) + 1*(x**2) + 1*x + 3
y_noise = 20 * np.random.normal(size=x.size)
ydata = y + y_noise
plt.plot(x, ydata,  'bo')
plt.plot(x,y, 'r') 
plt.ylabel('Dependent Variable')
plt.xlabel('Independent Variable')
plt.show()

Quadratic

x = np.arange(-5.0, 5.0, 0.1)

##You can adjust the slope and intercept to verify the changes in the graph

y = np.power(x,2)
y_noise = 2 * np.random.normal(size=x.size)
ydata = y + y_noise
plt.plot(x, ydata,  'bo')
plt.plot(x,y, 'r') 
plt.ylabel('Dependent Variable')
plt.xlabel('Independent Variable')
plt.show()

Exponential

An exponential function with base c is defined by $$ Y = a + b c^X$$ where b ≠0, c > 0 , c ≠1, and x is any real number. The base, c, is constant and the exponent, x, is a variable.

Logarithmic

The response is a results of applying the logarithmic map from the input to the output .
It is one of the simplest form of log(): i.e. $$ y = \log(x)$$

Please consider that instead of , we can use , which can be a polynomial representation of the values.
In general form it would be written as

X = np.arange(-5.0, 5.0, 0.1)

Y = np.log(X)

plt.plot(X,Y) 
plt.ylabel('Dependent Variable')
plt.xlabel('Independent Variable')
plt.show()

Sigmoidal/Logistic

X = np.arange(-5.0, 5.0, 0.1)

Y = 1-4/(1+np.power(3, X-2))

plt.plot(X,Y) 
plt.ylabel('Dependent Variable')
plt.xlabel('Independent Variable')
plt.show()

부족한 점이나 잘못 된 점을 알려주시면 시정하겠습니다 :>

'AI' 카테고리의 다른 글

KNN(K-Nearset Neighbors)  (0) 2023.07.07
Classification  (0) 2023.07.07
Polynomial Regression 실습  (0) 2023.07.06
Non-Linear Regression  (0) 2023.07.06
Multiple Linear Regression 실습  (0) 2023.07.06

댓글