Пакет `сантехник` R для развертывания моделей - PullRequest
0 голосов
/ 06 марта 2019

Я следую этому уроку

https://www.knowru.com/blog/how-create-restful-api-for-machine-learning-credit-model-in-r/

Я прохожу примерно половину, пока не столкнусь с ошибкой.

Error in plumb(dir = "deploy_ml_credit_model.R") : 
  No plumber.R file found in the specified directory: deploy_ml_credit_model.R

И (когда я удаляю dir = из последней строки, я получаю эту ошибку):

Error in parse(file, keep.source = TRUE) : 
  deploy_ml_credit_model.R:7:1: unexpected input
6: 
7: §
   ^
In addition: There were 50 or more warnings (use warnings() to see the first 50)

Я пытаюсь использовать RESTful API для подключения к простому дереву решений, но не понимаю, почему появляется ошибка.

CODE (я получаю ошибки в последних нескольких строках кода):

url <- "https://archive.ics.uci.edu/ml/machine-learning-databases/statlog/german/german.data"

col.names <- c(
  'Status of existing checking account', 'Duration in month', 'Credit history'
  , 'Purpose', 'Credit amount', 'Savings account/bonds'
  , 'Employment years', 'Installment rate in percentage of disposable income'
  , 'Personal status and sex', 'Other debtors / guarantors', 'Present residence since'
  , 'Property', 'Age in years', 'Other installment plans', 'Housing', 'Number of existing credits at this bank'
  , 'Job', 'Number of people being liable to provide maintenance for', 'Telephone', 'Foreign worker', 'Status'
)

# Get the data
data <- read.csv(
  url
  , header=FALSE
  , sep=' '
  , col.names=col.names
)


data



library(rpart)
# Build a tree
# I already figured these significant variables from my first iteration (not shown in this code for simplicity)
decision.tree <- rpart(Status ~ Status.of.existing.checking.account + 
                         Duration.in.month + Credit.history + 
                         Savings.account.bonds, method="class", data=data)



library(rpart.plot)
# Visualize the tree
# 1 is good, 2 is bad
prp(decision.tree, extra=1, varlen=0, faclen=0, main="Decision Tree for German Credit Data")


# We have a trained model and we dont need to "test" the predictions but here 
#we do just for completness

#create a new data entry from nothing
new.data <- list(Status.of.existing.checking.account='A11', 
                 Duration.in.month=20,
                 Credit.history='A32',
                 Savings.account.bonds='A65'
)

predict(decision.tree, new.data)


#save model to hard drive so we can use the RESTful API

save(decision.tree, file='decision_Tree_for_german_credit_data.RData')


# Using the R package Plumber to create a RESTful API



library(rpart)
library(jsonlite)


load("decision_Tree_for_german_credit_data.RData")


#* @post /predict
predict.default.rate <- function(Status.of.existing.checking.account,
                                 Duration.in.month,
                                 Credit.history,
                                 Savings.account.bonds)
{data <- list(Status.of.existing.checking.account = Status.of.existing.checking.account,
              Duration.in.month=Duration.in.month,
              Credit.history=Credit.history,
              Savings.account.bonds=Savings.account.bonds)
prediction <- predict(decision.tree, data)
return(list(default.probability=unbox(prediction[1, 2])))
}


# Save the model

save(decision.tree, file='deploy_ml_credit_model.R')


library(plumber)
r <- plumb(dir = "deploy_ml_credit_model.R")
r$run(port=8000)

EDIT:

Предупреждающие сообщения:

> warnings()
Warning messages:
1: In readLines(file) : line 3 appears to contain an embedded nul
2: In readLines(file) : line 4 appears to contain an embedded nul
3: In readLines(file) : line 5 appears to contain an embedded nul
4: In readLines(file) : line 6 appears to contain an embedded nul
5: In readLines(file) : line 7 appears to contain an embedded nul
6: In readLines(file) : line 8 appears to contain an embedded nul
7: In readLines(file) : line 9 appears to contain an embedded nul
8: In readLines(file) : line 10 appears to contain an embedded nul
9: In readLines(file) : line 11 appears to contain an embedded nul
10: In readLines(file) : line 12 appears to contain an embedded nul
11: In readLines(file) : line 13 appears to contain an embedded nul
12: In readLines(file) : line 14 appears to contain an embedded nul
13: In readLines(file) : line 15 appears to contain an embedded nul
14: In readLines(file) : line 16 appears to contain an embedded nul
15: In readLines(file) : line 17 appears to contain an embedded nul
16: In readLines(file) : line 18 appears to contain an embedded nul
17: In readLines(file) : line 19 appears to contain an embedded nul
18: In readLines(file) : line 20 appears to contain an embedded nul
19: In readLines(file) : line 21 appears to contain an embedded nul
20: In readLines(file) : line 22 appears to contain an embedded nul
21: In readLines(file) : line 23 appears to contain an embedded nul
22: In readLines(file) : line 24 appears to contain an embedded nul
23: In readLines(file) : line 25 appears to contain an embedded nul
24: In readLines(file) : line 26 appears to contain an embedded nul
25: In readLines(file) : line 27 appears to contain an embedded nul
26: In readLines(file) : line 28 appears to contain an embedded nul
27: In readLines(file) : line 29 appears to contain an embedded nul
28: In readLines(file) : line 30 appears to contain an embedded nul
29: In readLines(file) : line 31 appears to contain an embedded nul
30: In readLines(file) : line 32 appears to contain an embedded nul
31: In readLines(file) : line 33 appears to contain an embedded nul
32: In readLines(file) : line 34 appears to contain an embedded nul
33: In readLines(file) : line 35 appears to contain an embedded nul
34: In readLines(file) : line 36 appears to contain an embedded nul
35: In readLines(file) : line 37 appears to contain an embedded nul
36: In readLines(file) : line 38 appears to contain an embedded nul
37: In readLines(file) : line 39 appears to contain an embedded nul
38: In readLines(file) : line 40 appears to contain an embedded nul
39: In readLines(file) : line 41 appears to contain an embedded nul
40: In readLines(file) : line 42 appears to contain an embedded nul
41: In readLines(file) : line 43 appears to contain an embedded nul
42: In readLines(file) : line 44 appears to contain an embedded nul
43: In readLines(file) : line 45 appears to contain an embedded nul
44: In readLines(file) : line 46 appears to contain an embedded nul
45: In readLines(file) : line 47 appears to contain an embedded nul
46: In readLines(file) : line 48 appears to contain an embedded nul
47: In readLines(file) : line 49 appears to contain an embedded nul
48: In readLines(file) : line 50 appears to contain an embedded nul
49: In readLines(file) : line 51 appears to contain an embedded nul
50: In readLines(file) : line 52 appears to contain an embedded nul
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...