일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
- Python
- sklearn
- python3
- 데이터 분석
- 실기
- R
- matplotlib
- Oracel
- 빅분기
- level 2
- SQL
- 코딩테스트
- 카카오
- Numpy
- 실습
- 알고리즘
- seaborn
- level 1
- pandas
- 빅데이터 분석 기사
- 파이썬
- 머신러닝
- 튜닝
- 오라클
- Kaggle
- 프로그래머스
- oracle
- Today
- Total
목록sklearn (18)
라일락 꽃이 피는 날
1. StandardScaler 평균(mean)을 0, 표준편차(std)를 1로 만들어 주는 스케일러 from sklearn.preprocessing import StandardScaler std_scaler = StandardScaler() std_scaled = std_scaler.fit_transform(x_train) 2. MinMaxScaler min값과 max값을 0~1사이로 정규화 from sklearn.preprocessing import MinMaxScaler minmax_scaler = MinMaxScaler() minmax_scaled = minmax_scaler.fit_transform(x_train) 3. RobustScaler 중앙값(median)이 0, IQR(interquar..
ElasticNet l1_ratio (default=0.5) l1_ratio = 0 (L2 규제만 사용) l1_ratio = 1 (L1 규제만 사용) 0 < l1_ratio < 1 (L1 and L2 규제의 혼합사용) from sklearn.linear_model import ElasticNet ratios = [0.2, 0.5, 0.8] for ratio in ratios: elasticnet = ElasticNet(alpha=0.5, l1_ratio=ratio) elasticnet.fit(x_train, y_train) pred = elasticnet.predict(x_test) elsticnet_20 = ElasticNet(alpha=5, l1_ratio=0.2) elsticnet_20.fit(x_..
규제 (Regularization) 학습이 과대적합 되는 것을 방지하고자 일종의 penalty를 부여하는 것 L2 규제 (L2 Regularization) - 릿지(Ridge) - 각 가중치 제곱의 합에 규제 강도(Regularization Strength) λ를 곱한다. - λ를 크게 하면 가중치가 더 많이 감소되고(규제를 중요시함), λ를 작게 하면 가중치가 증가한다(규제를 중요시하지 않음). L1 규제 (L1 Regularization) - 라쏘(Lasso) - 가중치의 제곱의 합이 아닌 가중치의 합을 더한 값에 규제 강도(Regularization Strength) λ를 곱하여 오차에 더한다. - 어떤 가중치(w)는 실제로 0이 된다. 즉, 모델에서 완전히 제외되는 특성이 생기는 것이다. → L2..
LinearRegression from sklearn.linear_model import LinearRegression model = LinearRegression(n_jobs=-1) model.fit(x_train, y_train) pred = model.predict(x_test)
MSE(Mean Squared Error) 예측값과 실제값의 차이에 대한 제곱에 대하여 평균을 낸 값 MAE (Mean Absolute Error) 예측값과 실제값의 차이에 대한 절대값에 대하여 평균을 낸 값 RMSE (Root Mean Squared Error) 예측값과 실제값의 차이에 대한 제곱에 대하여 평균을 낸 뒤 루트를 씌운 값 평가 지표 함수로 만들기 import numpy as np pred = np.array([3, 4, 5]) actual = np.array([1, 2, 3]) def my_mse(pred, actual): return ((pred - actual)**2).mean() my_mse(pred, actual) # 4.0 def my_mae(pred, actual): retur..
오차 (Error) from sklearn.datasets import load_breast_cancer from sklearn.model_selection import train_test_split cancer = load_breast_cancer() data = cancer['data'] target = cancer['target'] (0-악성종양, 1-양성종양) feature_names=cancer['feature_names'] df = pd.DataFrame(data=data, columns=feature_names) df['target'] = cancer['target'] pos = df.loc[df['target']==1] neg = df.loc[df['target']==0] 양성 환자 357..
1. Logistic Regression 로지스틱 회귀는 독립 변수의 선형 결합을 이용하여 사건의 발생 가능성을 예측하는데 사용되는 통계 기법이다. 서포트 벡터 머신(SVM)과 같은 알고리즘은 이진 분류만 가능하다. (2개의 클래스 판별만 가능) 3개 이상의 클래스에 대한 판별을 진행하는 경우, 다음과 같은 전략으로 판별한다. ① one-vs-rest(OvR) K개의 클래스가 존재할 때 1개의 클래스를 제외한 다른 클래스를 K개 만들어, 각각의 이진 분류에 대한 확률을 구하고 총합을 통해 최종 클래스를 판별한다. ② one-vs-one(OvO) 4개의 계절을 구분하는 클래스가 존재한다고 가정했을 때, 0vs1, 0vs2, 0vs3, ... , 2vs3 까지 NX(N-1)/2개의 분류기를 만들어 가장 많이..
데이터 셋 (dataset) DESCR: dataset 정보 data: feature data feature_names: feature data의 컬럼 이름 target: label data (수치형) target_names: label의 이름 (문자형) from sklearn.datasets import load_iris iris = load_iris() data = iris['data'] feature_names = iris['feature_names'] target = iris['target'] 데이터프레임 생성 df_iris = pd.DataFrame(data, columns=feature_names) df_iris['target'] = target train / validation 세트 나누기 ..