►
From YouTube: Using ML.NET in an Azure Function for Predictions
Description
Using ML.NET in an Azure Function with an HTTP Trigger to perform predictions on a previously build ML.NET model.
Code that saves the model file - https://github.com/jwood803/MLNET-HousingRegression/tree/master/HouseRegression/HouseRegression
Azure function code - https://github.com/jwood803/MLNetExamples/tree/master/MLNetExamples/AzureFunction
ML.NET Web API video - https://www.youtube.com/watch?v=FFvpEeWW7AQ
Contact:
Twitter: https://twitter.com/JWood/
Blog: https://jonwood.co/
Gear used (affiliate links):
Mic - https://amzn.to/2YEXtxI
Mouse - https://amzn.to/2ZtASoQ
A
Hey
everyone
so
a
while
back
I
had
a
video
where
I
showed
how
to
create
a
Web
API
that
can
be
used
to
load
in
a
name
on
that
net
model
and
that
was
within
an
demo
done
an
Indian
series,
but
with
the
increasing
in
popularity
of
service
in
this
video
I'll
show
how
to
create
an
azure
function
that
can
make
predictions.
You
can
use
that
function
within
your
other
applications,
similar
to
what
you
will
use
with
that
Web
API,
all
right
so
I'm
in
visual
studio
here,
I
don't
have
any
projects
loaded.
A
A
All
right,
I'm
gonna
leave
this
function,
a
certain
is
preloaded
and
I.
Add
some
new
get
packages
first
things.
First,
we
install
ml
net
using
version
1.3
point
1
here
and
for
dessert
function.
We
need
to
install
microsoft
extensions,
that
ml
and
since
we're
going
to
interact
with
blob
storage,
I'm
gonna
download
that
as
also
alright,
so
I'm
gonna
add
a
new
order.
Function,
I'm
not
call
this
housing
predict
alright
and
this
and
then
take
out
the
gift,
because
it's
going
to
be
a
post
need
to
post
in
some
data
for
it
to
take
in.
A
So
we
can
predict
on
that
data.
Alright,
so
I
mentioned
I'm
gonna
used
as
your
storage.
So
so,
if
you
look
in
my
as
your
storage
account
with
the
storage
Explorer
here,
I'm
in
the
models
container
and
I
have
this
housing
model,
that's
it
and
real,
quick.
Let's
actually
look
at
the
code
that
generated
this
model
phone.
A
The
code
that
generated
that
model
file
here
the
data
I'm
using
is
the
California
housing
prices.
Here
has
some
attributes
of
the
area
and
the
houses
within
the
area
such
as
latitude
longitude,
the
median
age,
total
rooms,
total
bedrooms,
population
of
that
area,
and
what
we're
going
to
predict
is
the
median
house
value
based
on
these
other
properties,
real,
quick,
we'll
go
through
here.
We
load
the
text
from
data,
it
has
a
header
and
we'll
give
it
a
separator.
A
We
generate
the
features-
and
we
use
some
link
here
to
do
that
within
the
data
that
we
got
from
the
text
file.
We
get
a
schema
and
with
the
schema
we
can
get
the
column
name
from
there
and
we
just
filter
out
where
the
call
name
is
label
and
it's
playable,
because
we
specify
that
in
the
housing
data
schema
here,
the
median
house
value
has
to
call
name
the
label
and
I
don't
use
the
ocean
proximity
here
either
because
it's
not
a
numeric
feature
column.
It's
a
string
column.
A
So
we'll
do
something
separate
with
that
and
we
send
it
to
an
array
and
then,
in
our
pipeline
here
we
fit
Rosco
text,
the
ocean
proximity
text
and
we
set
it
to
a
new
column
called
text.
And
then
we
just
concatenate
all
these
features
from
up
here
to
a
column
name
features
then
use
the
Poisson
regression
trainer
and
we
append
that
to
the
state
of
pipeline
and
then
we
fit
on
it,
and
then
we
just
save
that
model
out,
and
then
we
manually
put
that
into
our
reserve
blob
storage.
A
So
with
that,
we
first
need
to
actually
get
a
reference
to
that
model
file
to
send
blob
storage.
So
to
do
that
in
the
ensure
function,
I'm
going
to
add
a
new
class,
and
this
is
going
to
be
kind
of
a
startup
class
that
runs
every
time
or
as
your
function
starts
up,
and
for
this
to
run
every
time
the
function
starts
up,
we
need
to
inherit
from
functions,
start
up
base
class.
A
It's
actually
I
forgot
to
install
an
additional
NuGet
package.
We
also
need
the
Microsoft
Azure
def
functions,
extensions,
NuGet
package
and
that,
with
that
that'll
have
that
function
start
up
class
that
we
need
very
good,
and
this
requires
an
abstract
class
that
we
need
to
fill
in
call
configure,
and
it
gives
us
this
functions
host
builder
and
within
here
when
you
start
to
build
out
our
connection
to
the
blob
storage.
A
So
we
can
get
that
pretty
easily
here
by
using
environment,
get
environment
variable,
and
we
can
use
that
as
your
web
jobs
storage
key
that
we
just
saw
and
I'm
going.
To
put
this
me
environment
variable
target
is
process,
so
we
have
our
connection
string.
Now
we
need
to
create
storage
account
using
the
cloud
storage
account.
A
A
And
then
I'm
gonna
actually
get
the
URL
of
this
file
to
model
that
you're
on
that
absolute,
your
I,
and
here
this
is
where
we
used
to
end
all
that
extensions
from
that
builder
that
we
get
in
the
construction
in
a
constructor
up
here.
That
has
a
services
that
add
prediction:
engine
full
extension
method.
A
A
This
is
going
to
be
the
housing
data
class
and
I'm
just
going
to
paste
this
in.
So
you
don't
see
me
typing
in
all
this,
then
I'm
gonna
do
the
same
thing
for
the
housing
predict
for
the
housing
prediction
clouds-
and
this
is
just
I'm.
Gonna-
have
a
predictive
price
property
on
it,
and
it's
gonna
have
the
call
name,
a
score
for
the
email
net
engine
so
Andy's
here
and
then
that
can
tell
it
either
from
an
actual
file
which
you
can
use.
A
That's
all
we
need
to
do
for
our
start
up,
and
what
this
does
is
that
it
creates
kind
of
a
reference.
First
of
all,
it
creates
our
prediction
function.
If
you
member
saying
in
the
previous
videos,
we
create
a
prediction
function
and
from
that
prediction
function,
that's
what
we
used
to
actually
call
to
predict
function
until
I.
Go
back
to
our
function
here
and
I
need
to
remove
these
statics
because
I
need
to
add
a
constructor,
and
this
is
going
to
bring
in
the
prediction
engine
pool
for
housing
data
and
housing.
A
And
then
I'm
just
gonna
have
the
constructor
said
that
that
field
from
my
guest
pass
in
so
now
we
have
access
to
the
prediction.
Engine
pool
within
this
whole
class
that
can
use
it
within
this
function.
I'll
go
ahead
and
delete
all
this,
but
it
shows
you
how
to
I
can
get
information
from
either
the
query
parameter
or
from
the
request
body
and
we'll
begin
it
from
the
request
body.
A
Next,
we
need
to
parse
our
data
difficut
from
the
body,
so
do
Jason
Jason
convert
these
serial
lives
object
into
the
housing
data
object,
giving
the
quest
body
string
now
that
we
can
get
our
prediction
by
calling
the
prediction
engine
board,
I
predict
and
passing
the
housing
data
that
we
DC
realized
and
they
return
back.
Jason
object.
We
return
a
new,
ok
object,
result
just
passing
the
prediction.
A
Well
that
looks
okay.
We
can
test
this
locally
just
by
running
it
within
Visual
Studio.
There
we
go,
and
it
gives
us
a
URL
that
we
can
use
to
test
locally
here
and
to
do
that,
since
it's
a
post
method,
we
used
postman,
so
here's
postman
I
already
have
it
said
to
do
a
post
request
and
I
have
the
header,
as
for
the
content
type
as
Jason
and
I'll
just
paste
in
that
URL.
A
That
I
gave
us
in
the
output
and
for
the
body
under
your
role
and
set
it
to
Jason
for
the
body
I'll
just
give
it
some
kind
of
random
values
for
our
features
that
we
have
there
and
we
just
hit
sin,
see
we're
getting
an
error
here,
unable
to
resolve
service
for
a
type
prediction
engine
pool.
Well,
we
actually
forgot
something
on
our
startup
here.
A
We
need
to
tell
this
namespace
to
actually
start
up
when
that
function
starts
up,
so
it
doesn't
know
that
by
default,
so
in
the
top
of
the
namespace
would
do
assembling
your
D
functions,
startup
type
of
startup.
So
now
let's
try
this
again
when
you
open
at
the
same
URL
that
we
did
before
so
it
hits
in
there.
You
never
get
to
predict
the
price
result
from
that,
so
that's
cool
locally,
but
let's
actually
deploy
this
to
adjourn,
so
we
can
use
it
and
any
other
applications
without
having
to
this
function,
to
run
locally.
A
So
stop
debugging
and
it's
real
easy
to
to
deploy
this
function
in
the
project.
Right.
Click
on
it
and
hit,
publish
I'll,
create
a
new
there's,
your
app
service
for
it
and
I'll
click
run
from
package
file.
You
just
basically
zips
up
everything,
clear,
publish
and
I
already
logged
into
your
account.
I'll,
give
it
an
app
name
so
we're
resource
group
to
go
on,
give
it
a
hosting
plan.
I
can
tell
it
to
do
a
new
one.
If
I
want
I'm
gonna
designate
that
same
storage
calendar,
we
used
all
right
now.
A
Quick
great,
yes,
will
probably
take
a
few
minutes
to
deploy
everything.
That's
how
I
function
got
deployed
here,
I'm
in
the
azure
portal,
with
inside
the
the
function
that
we
just
deployed
and
here's
that
housing
predict
function
there.
You
can
click
on
it.
We
can
click
run
if
you
want
to
just
test
us
locally
and
we
can
give
it
that
same
body
that
we
just
did
and
click
run.
I'm
gonna
guess
is
that
same
predict
the
price
output.
A
But
if
you
want
to
run
this
within
another
application,
we
just
click.
This
get
function,
URL
and
copy
it,
and
we
go
back
to
postman
here.
Just
replace
that
and
hits
in
there
we
go.
We
get
the
same,
predict
the
price
output
that
we
did
before.
So
that's
how
you
can
create
a
new
function
and
use
mo
dinette
predictions
to
predict
on
model
file
that
you
have
already
created
and
we
also
went
over
held
to
I
can
deploy
and
how
easy
it
was
to
deploy
the
function
to
assure
alright.