Created
October 7, 2017 21:53
-
-
Save edgararuiz-zz/d8de6b9574c8e6950e279db1bc0ce8ed to your computer and use it in GitHub Desktop.
This file contains 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
library(tfestimators) | |
library(titanic) | |
library(dplyr) | |
library(purrr) | |
titanic_set <- titanic_train %>% | |
filter(!is.na(Age)) | |
glimpse(titanic_set) | |
titanic_input_fn <- function(data) { | |
input_fn(data, | |
features = c("Sex", | |
"Pclass", | |
"Embarked"), | |
response = "Survived") | |
} | |
cols <- feature_columns( | |
column_categorical_with_vocabulary_list("Sex", vocabulary_list = unique(titanic_set$Sex) %>% map(~.x)), | |
column_categorical_with_vocabulary_list("Embarked", vocabulary_list = unique(titanic_set$Embarked) %>% map(~.x)), | |
column_numeric("Pclass") | |
) | |
model <- linear_classifier(feature_columns = cols) | |
indices <- sample(1:nrow(titanic_set), size = 0.80 * nrow(titanic_set)) | |
train <- titanic_set[indices, ] | |
test <- titanic_set[-indices, ] | |
train(model, titanic_input_fn(train)) | |
model_eval <- evaluate(model, titanic_input_fn(test)) | |
model_predict <- predict(model, titanic_input_fn(test)) | |
tensorboard(model$estimator$model_dir, launch_browser = TRUE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment