Predict with Elixir

1. Install.

Add the modelfox package to your mix.exs.

2. Predict.

First, import the modelfox library and load the model file. Then, make an object with info for a new patient that matches the CSV, excluding the diagnosis column. Finally, call predict and print out the result.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# Get the path to the .modelfox file. # In your application, you will probably want to put your .modelfox file in your mix package's `priv` # directory and read it like this: `Path.join(:code.priv_dir(:your_app_name), "model.modelfox")`. model_path = Path.join(Path.dirname(__ENV__.file), "heart_disease.modelfox") # Load the model from the path. model = ModelFox.load_model_from_path(model_path) # Create an example input matching the schema of the CSV file the model was trained on. # Here the data is just hard-coded, but in your application you will probably get this # from a database or user input. input = %{ :age => 63.0, :gender => "male", :chest_pain => "typical angina", :resting_blood_pressure => 145.0, :cholesterol => 233.0, :fasting_blood_sugar_greater_than_120 => "true", :resting_ecg_result => "probable or definite left ventricular hypertrophy", :exercise_max_heart_rate => 150.0, :exercise_induced_angina => "no", :exercise_st_depression => 2.3, :exercise_st_slope => "downsloping", :fluoroscopy_vessels_colored => "0", :thallium_stress_test => "fixed defect" } # Make the prediction! output = ModelFox.predict(model, input) # Print the output. IO.write("Output: ") IO.inspect(output)