This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import roc_curve | |
import matplotlib.pyplot as plt | |
pred_proba = lr_clf.predict_proba(x_test)[:, 1] | |
fprs, tprs, thresholds = roc_curve(y_test, pred_proba) | |
thr_index = np.arange(1, thresholds.shape[0], 5) | |
print('index:',thr_index) | |
print('threshold:',thresholds[thr_index]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import precision_recall_curve | |
pred_proba_class1 = lr_clf.predict_proba(x_test)[:,1] | |
precisions, recalls, thresholds = precision_recall_curve(y_test, pred_proba_class1) | |
print(thresholds.shape) | |
print(thresholds) | |
thr_idx = np.arange(0, thresholds.shape[0], 15) | |
print(thr_idx) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.metrics import confusion_matrix | |
confusion_matrix(y_test, prediction) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import MinMaxScaler | |
scaler = MinMaxScaler() | |
scaler.fit(iris_df) | |
iris_scaled = scaler.transform(iris_df) | |
# 역시나 transform() 결과가 ndarray라 DataFrame으로 바꿔준다. | |
df_scaled = pd.DataFrame(iris_scaled, columns=iris.feature_names) | |
print('[최솟값]') | |
print(df_scaled.min()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.datasets import load_iris | |
from sklearn.preprocessing import StandardScaler | |
import pandas as pd | |
iris = load_iris() | |
iris_df = pd.DataFrame(data=iris.data, columns=iris.feature_names) | |
print('#####BEFORE#####') | |
print('[mean]\n', iris_df.mean()) | |
print('\n[var]\n', iris_df.var()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
items = pd.DataFrame(['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서'], columns=['items']) | |
print(items) | |
pd.get_dummies(items) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import OneHotEncoder, LabelEncoder | |
import numpy as np | |
items = ['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서'] | |
# 숫자 값으로 변환하기 위해 LabelEncoder로 먼저 변환한다. | |
encoder = LabelEncoder() | |
encoder.fit(items) | |
labels = encoder.transform(items) | |
print(labels) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
print('classes:', encoder.classes_, '\n') | |
print('decoding:', encoder.inverse_transform(labels)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.preprocessing import LabelEncoder | |
items = ['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서'] | |
# LabelEncoder 객체 생성 후 fit( )과 transform( ) 적용 | |
encoder = LabelEncoder() | |
encoder.fit(items) | |
labels = encoder.transform(items) | |
print(labels) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Global LR computed on polynomial decay schedule | |
decay = (1 - float(epoch) / max_epoch) ** 2 | |
global_lr = lr * decay | |
# 코드출처:https://github.com/noahgolmant/pytorch-lars/blob/master/lars.py |
NewerOlder