Skip to content

Instantly share code, notes, and snippets.

View 2-Chae's full-sized avatar
🦄
dreaming

Chaehyeon Lee 2-Chae

🦄
dreaming
View GitHub Profile
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])
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)
from sklearn.metrics import confusion_matrix
confusion_matrix(y_test, prediction)
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())
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())
import pandas as pd
items = pd.DataFrame(['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서'], columns=['items'])
print(items)
pd.get_dummies(items)
from sklearn.preprocessing import OneHotEncoder, LabelEncoder
import numpy as np
items = ['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서']
# 숫자 값으로 변환하기 위해 LabelEncoder로 먼저 변환한다.
encoder = LabelEncoder()
encoder.fit(items)
labels = encoder.transform(items)
print(labels)
print('classes:', encoder.classes_, '\n')
print('decoding:', encoder.inverse_transform(labels))
from sklearn.preprocessing import LabelEncoder
items = ['TV', '냉장고', '전자렌지', '컴퓨터', '선풍기', '선풍기', '믹서', '믹서']
# LabelEncoder 객체 생성 후 fit( )과 transform( ) 적용
encoder = LabelEncoder()
encoder.fit(items)
labels = encoder.transform(items)
print(labels)
# 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