Skip to content

Instantly share code, notes, and snippets.

View gamamoe's full-sized avatar

Geunho Lee gamamoe

View GitHub Profile
@gamamoe
gamamoe / line-graph-ggplot2.R
Created April 7, 2020 12:57
Line graph example using ggplot2
library(readr)
library(ggplot2)
path <- "/foo/bar/baz"
df <- read_csv(path, col_types = cols(Count = col_integer()))
cbPalette <- c("#E69F00", "#009E73", "#000000", "#0072B2", "#D55E00", "#CC79A7")
plot <- ggplot(data = df, aes(x = Date, y = Count, group = Tag, colour = Tag)) +
theme(plot.title = element_text(size = 24, face = "bold"),
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstdint>
#include <string>
typedef std::vector<std::vector<int>> Table;
typedef std::vector<int> Path;
struct NodesInShortestPath {
test_matrix = randi(10, 10, 10) # 10 by 10 matrix
check_numeric = 3
equality_check_matrix = (test_matrix == check_numeric)
result = test_matrix .* equality_check_matrix
na_expression <- c(1, 5, 10)
# data.frame
data_frame <- data.frame(x = 1:10, y = 5:14, z = 10:19)
for (element in na_expression) {
data_frame[data_frame == element] <- NA
}
# 하나의 값을 NA로 변환할 때
element <- 0
dt[dt == element] <- NA
# 여러 개의 값을 NA로 변환할 때
na_expression <- c(0, 1, 2)
for (element in na_expression) {
dt[dt == element] <- NA
}
# Multilayer Perceptron (MLP) 생성
model = Sequential()
# Dense(256)의 의미는 256개의 hidden unit을 가지는 fully connected layer
# keras에서는 첫 번째 Layer, 즉 input layer의 input dimension만 지정하면
# 뒤의 연결되는 Layer의 dimension은 간단하게 작성 가능하다.
# width * height = 784인 dimension
# glorot_uniform == Xavier Initialization, keras에서는 내부적으로 이미 제공
# 데이터 Load 및 전처리 과정
# Train, Test 데이터 Load
(X_train, y_train), (X_test, y_test) = mnist.load_data()
# Train 데이터 포맷 변환
# 60000(Train Sample 수) * 28(가로) * 28(세로) 포맷을
# 60000(Train Sample 수) * 784(= 28 * 28) 포맷으로 수정
num_of_train_samples = X_train.shape[0] # Train Sample 수
width = X_train.shape[1] # 가로 길이
# MNIST 데이터 관련 import
from keras.datasets import mnist # MNIST 데이터 Loader
from keras.utils.np_utils import to_categorical # One-hot 포맷 변환
import numpy as np # float type casting
# Feature scaling 관련 import
from sklearn.preprocessing import minmax_scale # [0-1] Scaling
# Model 구축 관련 import
from keras.models import Sequential
#include "my_array.h"
MyArray::MyArray() {
size_ = 0;
last_element_index_ = -1;
ptr_ = NULL;
}
MyArray::MyArray(int initial_size) {
size_ = initial_size;
#ifndef MY_ARRAY_H_
#define MY_ARRAY_H_
#include <cstring>
#include <iostream>
class MyArray {
public:
MyArray();
MyArray(int initial_size);