라이브러리
-
torch.utils.data라이브러리/PyTorch 2022. 3. 7. 14:04
torch.utils.data torch.utils.data module하에는 torch가 제공하는 여러 데이터셋과 DataLoader class를 제공하는데, 이는 추상화와 유연하게 구현하는데 도움을 준다. torch.utils.data.DataLoader 예시는 다음과 같다. form torch.utils.data import TensorDataset, DataLoader train_ds = TensorDataset(X_train, y_train) train_dl = DataLoader(train_ds, batch_size=bs) for x_batch, y_batch in train_dl: pred = model(x_batch) ###### # 다음과 같이 batch를 iterate할 필요 없다. f..
-
torch.optim라이브러리/PyTorch 2022. 3. 7. 14:00
torch.optim back-progate 함으로써 NN의 weight를 업데이트 하는 과정을 optimization이라 한다. torch.optim module은 optimization schedule 에 대한 다양한 툴과 기능을 포함한다. 다음과 같이 torch.optim module을 이용해 optimizer를 정의할 수 있다. import torch opt = torch.optim.SGD(model.parameters(), lr=lr) 그리고나서 optimization 수행을 다음과 같이 하면 된다. opt.step() opt.zero_grad() ##### 다음과 같이 할 필요 없다. with torch.no_grad(): # applying the parameter updates uisng ..
-
torch.nn라이브러리/PyTorch 2022. 3. 7. 13:56
torch.nn torch.nn enables ueres to quickly instantiate NN architectures by defining some of these high-level aspects as opposed to having to specify all the details manually. import math import torch # assume a 256-dimensional input and a 4-dimensional output for this 1-layer NN # hence, initialize a 256x4 dimensional matrix filled with random values weights = torch.randn(256, 4) / math.sqrt(256..
-
Exager execution라이브러리/PyTorch 2022. 3. 7. 13:44
Tensorflow vs. PyTorch The initial difference between these two was that PyTorch was based on eager execution whereas TensorFlow was built on graph-based deferred execution. Although, TensorFlow now also provides an eager execution mode. Eager execution is basically an imperative programming mode where mathematical operations are computed immediately. A deferred execution mode would have all the..
-
tf.data, TFRecord라이브러리/Tensorflow keras 2022. 1. 5. 00:32
tf.data https://www.tensorflow.org/guide/data The tf.data API enables you to build complex input pipelines from simple, reusable pieces. For example, the pipeline for an image model might aggregate data from files in a distributed file system, apply random perturbations to each image, and merge randomly selected images into a batch for training. The pipeline for a text model might involve extrac..
-
Model vs Estimator라이브러리/Tensorflow keras 2022. 1. 3. 17:01
Background The Estimators API was added to Tensorflow in Release 1.1, and provides a high-level abstraction over lower-level Tensorflow core operations. It works with an Estimator instance, which is TensorFlow's high-level representation of a complete model. Keras is similar to the Estimators API in that it abstracts deep learning model components such as layers, activation functions and optimiz..
-
Cross validation에서 ROC AUC 구하기라이브러리/Scikit-learn 2021. 2. 14. 20:44
StratifiedKFold을 통해 cross validation할 데이터 생성 from sklearn.linear_model import LogisticRegression from sklearn.model_selection import cross_val_score, StratifiedKFold cv = StratifiedKFold(n_splits=5,shuffle=False) 각 cv별 fpr(False Positive Rate), tpr(True Positive Rate) 및 auc(Area under the ROC Curve) 계산 및 평균 계산 logit = LogisticRegression(fit_intercept=True) tprs = [] aucs = [] mean_fpr_lr = np.li..
-
Cross validation에서 Confusion Matrix을 Metric으로 사용하기라이브러리/Scikit-learn 2021. 2. 14. 20:24
여기서 clf는 model, x는 학습 데이터, y는 x의 label 대신 from sklearn.model_selection import cross_val_predict from sklearn.metrics import confusion_matrix y_pred = cross_val_predict(clf, X, y, cv=5) conf_mat = confusion_matrix(y, y_pred) 이 값을 시각화 하는 방법은 다음과 같다. from sklearn.model_selection import cross_val_predict from sklearn.metrics import confusion_matrix from sklearn.metrics import ConfusionMatrixDisplay ..