Facebook star ratings prediction.
What is this project about?
Basic "hello world" example to:
- Compose ratings prediction model for on-boarding to Acumos marketplace.
- Script to test model locally.
Use cases
- Social media optimization
- Brand expansion
- Predictive real estate model
Training data
Training data was curated from Facebook Graph Search by searching for keyword "burgers". Places without parking and restaurant features were excluded. More data could be obtained by searching for other keywords or by adding location filters. For this project, a small amount of training data was sufficient to test Acumos workflow.
How to run it?
- Install Docker, R and Python.
- Install Acumos library for R one time.
- Run composer.R script to compose model file.
- On-board model to Acumos portal.
- Download on-boarded model for local testing.
- Run Docker micro-service container.
- Run Python script to test prediction against micro-service.
Run Docker micro-service container.
$ docker load -i facebookstarratings_a54da5e1-3603-46bc-ab89-f7d07f5d1147_1.tar
Loaded image: acumos-devchallenge-nexus:18001/facebookstarratings_a54da5e1-3603-46bc-ab89-f7d07f5d1147:1
$ docker run -p 3330:3330 acumos-devchallenge-nexus:18001/facebookstarratings_a54da5e1-3603-46bc-ab89-f7d07f5d1147:1
-- running Rserve in this R session (pid=1), 1 server(s) --
(This session will block until Rserve is shut down)
Run Python script to test prediction against micro-service.
$ python test/predict.py
Be sure to run Docker micro-service before running this test script, e.g.:
docker load -i facebookstarratings_a54da5e1-3603-46bc-ab89-f7d07f5d1147_1.tar
docker run -p 3330:3330 acumos-devchallenge-nexus:18001/facebookstarratings_a54da5e1-3603-46bc-ab89-f7d07f5d1147:1
#=============================================================================#
# --- Restaurant Features --- #
Price: $
Catering: No
Delivery: No
Groups: Yes
Kids: Yes
Outdoors: Yes
Reservations: No
Takeout: Yes
Walkins: Yes
Waiters: Yes
Lot Parking: No
Street Parking: Yes
Valet Parking: No
#=============================================================================#
#=============================================================================#
# --- Prediction --- #
Probability of restaurant having >=4 rating: 0.87276280000479
#=============================================================================#
$
Test prediction with different inputs in predict.py script.
pi.price_Xrange.append("$")
pi.restaurant_Xservices_Xdelivery.append(0)
pi.restaurant_Xservices_Xcatering.append(0)
pi.restaurant_Xservices_Xgroups.append(1)
pi.restaurant_Xservices_Xkids.append(1)
pi.restaurant_Xservices_Xoutdoor.append(1)
pi.restaurant_Xservices_Xreserve.append(0)
pi.restaurant_Xservices_Xtakeout.append(1)
pi.restaurant_Xservices_Xwaiter.append(1)
pi.restaurant_Xservices_Xwalkins.append(1)
pi.parking_Xlot.append(0)
pi.parking_Xstreet.append(1)
pi.parking_Xvalet.append(0)
Optional technical coding stuff
How was the Python file component_pb2.py used in predict.py created?
Acumos micro-service uses protocol buffer from Google. Protocol buffer is a way of translating object state into formats that could be sent over networks. Similar to older protocols like SOAP, which is not widely used anymore compared to JSON. The first step is to download protobuf from Github.
Unfortunately, protobuf is in C source code and must be compiled to produce binaries. In protobuf directory, run ./configure and then run make.
If make in step #2 runs without errors, there should be a protoc binary created under src directory. Copy that file to /usr/local/bin/ or another location on the system path.
The component.amc file generated by composer.R script is just a zip file.
$ unzip -l component.amc Archive: component.amc Length Date Time Name -------- ---- ---- ---- 42370 07-23-18 16:12 component.bin 675 07-23-18 16:12 meta.json 853 07-23-18 16:12 component.proto -------- ------- 43898 3 filesExtract component.proto from the zip file. Then run protoc with component.proto as argument. For Python code, the command looks like this.
$ protoc --python_out=. component.protoNow the file component_pb2.py is created with header like this.
# Generated by the protocol buffer compiler. DO NOT EDIT! # source: component.proto
Log in or sign up for Devpost to join the conversation.