일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
- 데이터분석
- 머신러닝
- 크롤링
- 42서울
- Computer Vision
- 선형대수학
- CV
- 인공지능
- 지정헌혈
- 코딩애플
- mnist
- 자연어처리
- 모델
- Flutter
- 크롤러
- 유데미
- 플러터
- 회귀
- AI
- RNN
- 피플
- 42경산
- 앱개발
- pytorch
- map
- filtering
- Regression
- 파이썬
- 딥러닝
- 선형회귀
- Today
- Total
David의 개발 이야기!
Polynomial Regression 다항회귀에 대해 알아보자! 본문
Polynomial Regression 다항회귀에 대해 알아보자!
david.kim2028 2022. 9. 12. 16:21연차에 따라 올라가는 임금을 알아보는 모델을 만들어보자!
1. Importing the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
2. Importing the dataset
dataset = pd.read_csv("Position_Salaries.csv")
x = dataset.iloc[:,1:-1].values
y = dataset.iloc[:,-1].values
3. Training the Polynomial Regression model on the whole dataset
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree=2)
x_poly = poly_reg.fit_transform(x)
from sklearn.linear_model import LinearRegression
regressor = LinearRegression()
regressor.fit(x_poly, y)
* PolynomialFeatures
-> Generate polynomial and interaction features.
Generate a new feature matrix consisting of all polynomial combinations of the features with degree less than or equal to the specified degree. For example, if an input sample is two dimensional and of the form [a, b], the degree-2 polynomial features are [1, a, b, a^2, ab, b^2].
-> parameters : degree
int or tuple (min_degree, max_degree), default=2
If a single int is given, it specifies the maximal degree of the polynomial features. If a tuple (min_degree, max_degree) is passed, then min_degree is the minimum and max_degree is the maximum polynomial degree of the generated features. Note that min_degree=0 and min_degree=1 are equivalent as outputting the degree zero term is determined by include_bias.
4. Visualizing the Polynomial Regression Result
plt.scatter(x, y, color='red')
plt.plot(x, regressor.predict(x_poly), color='blue')
5. Predicting new result with Polynomial Regression
regressor.predict(poly_reg.fit_transform([[6.5]]))
predict 안에 6.5 가 바로 들어가는게 아님을 주의하자!
'Udemy Python Machine Learning A-Z' 카테고리의 다른 글
의사결정트리 회귀에 대해 알아보자! (0) | 2022.11.10 |
---|---|
SVR 서포트벡터머신 체험하기! (0) | 2022.09.14 |
[ 파트2 섹션7 ] Multiple Linear Regression 다중선형회귀에 대해 알아보자! (0) | 2022.09.11 |
[파트2 섹션6] 단순회귀 Simple Regression (0) | 2022.09.11 |
데이터 전처리 fit, fit_transform, transform의 개념 익히기! (0) | 2022.09.09 |