회귀분석 응용RM ~ LSTAT 두 변수를 이용한 다중회귀분석 # Price ~ RM + LSTAT + RM**2 + RM * LSTAT + LSTAT**2# Price = b0 + b1 * rm + b2 * lstat + b3 * rm**2 + b4 * rm * lstat + b5 * lstat **2# 학습 세트에 다항식항(컬럼)을 추가X_train_rm_lstat_poly = poly.fit_transform(X_train_rm_lstat)# 테스트 세트에 다항식항(컬럼)을 추가X_test_rm_lstat_poly = poly.fit_transform(X_test_rm_lstat)print(X_test_rm_lstat_poly[:2])lin_reg.fit(X_train_rm_lstat_poly, y..
분류 전체보기
import sklearn.datasetsimport numpy as npimport matplotlib.pyplot as pltfrom sklearn.linear_model import LinearRegressionfrom sklearn.metrics import mean_squared_error, r2_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.preprocessing import PolynomialFeatures # 보스턴 집값 데이터 세트 로딩skl_data = sklearn.datasets.load_boston(return_X_y=False)print(type(skl_data)) # Bunch: 파이썬의 Dict와..
y = b + a * x: linear regressiony = b + a1 * x + a2 * x^2 -> 선형 회귀로 b, a1, a2를 결정할 수 있다. y = b + a1 * x1 + a2 * x2: 선형 회귀y = b + a1 * x1 + a2 * x2 + a3 * x1^2 + a4 * x1 * x2 + a5 * x2^2 import numpy as npimport matplotlib.pyplot as plt # Training Set - data : 범위 -3
import numpy as npimport matplotlib.pyplot as pltfrom sklearn.linear_model import LinearRegression 임의의 X, y 값 설정np.random.seed(1216)X = 2 * np.random.rand(100, 1)print('X shape:', X.shape) # 0.0 ~ 2.0 숫자들로 이루어진 100x1 행렬(2차원 ndarray) y = 4 + 3 * X + np.random.randn(100, 1)print('y shape', y.shape) X shape: (100, 1)y shape (100, 1) plt.scatter(X, y)plt.show() X_b = 행렬 [1 , X]로 구성 X_b = np.c_[np.on..