import mathimport matplotlib.pyplot as pltimport numpy as np def odds(p): """성공확률 / 실패확률""" return p / (1 - p) def log_odds(p): """odds에 log를 취한 값""" return math.log(odds(p)) def sigmoid(t): """logistic: log_odds(odds에 log를 취한 값)을 알고 있을 때, 성공 확률 p를 계산""" return 1 / (1 + math.exp(-t)) p = 0.8print(f'p = {p}, odds(p) = {odds(p)}, log_odds(p) = {log_odds(p)}')p = 0.8, odds(p) = 4.000000000000001, l..
Python
from sklearn import datasetsimport pandas as pdimport seaborn as snsimport matplotlib.pyplot as plt iris = datasets.load_iris()X = iris['data'] # iris.datay = iris['target'] # iris.targetfeatures = iris['feature_names'] # iris.feature_namesprint(features)['sepal length (cm)', 'sepal width (cm)', 'petal length (cm)', 'petal width (cm)'] iris_df = pd.DataFrame(X,columns=['sepal_length', 'sepal_wid..
import seaborn as snsimport matplotlib.pyplot as pltfrom sklearn.datasets import load_bostonimport pandas as pd boston = load_boston()X = boston['data'] # boston.datay = boston['target'] # boston.targetfeatures = boston['feature_names'] # boston.feature_names # DataFrame으로 변환boston_df = pd.DataFrame(X, columns = features, index= None) boston_df['Price'] = yprint(boston_df.head())print(boston_df...
회귀분석 응용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..