Created
April 13, 2020 18:21
-
-
Save George3d6/66a96a7ad255a19f014b0f8d79312f8f 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
import requests | |
root_url = 'http://localhost:47334' | |
# Spcify the training data and the value you want predicted | |
train_data_url = 'https://raw.githubusercontent.com/mindsdb/mindsdb-examples/master/benchmarks/heart_disease/processed_data/train.csv' | |
train_data = { | |
'to_predict': 'target', | |
'from_data': train_data_url | |
} | |
# Run a statistical analysis of the data to gather insights about it | |
response = requests.request('GET', f'{root_url}/predictors/any/analyse_dataset', params=train_data) | |
print(response.text) | |
# Create a Predictor (this will automatically start training the Predictor with the training data specified to predicted the outputs) | |
predictor_name = 'heart_disease_predictor' | |
response = requests.request('PUT', f'{root_url}/predictors/{predictor_name}', json=train_data) | |
print(response.text) | |
# Get a prediction based on some incomplete data | |
test_data = { | |
'when': { | |
'age': '25', | |
'sex': '0', | |
'chol': '150', | |
'thalach': '170', | |
'exang': '0', | |
'fbs': '0', | |
'thal': '3', | |
}, | |
'format_flag': 'new_explain' # The format of the returned predictions, new_explain is the best one currently, I recommend only using this, other format serve backwards compatibility purposes | |
} | |
response = requests.request('POST',f'{root_url}/predictors/{predictor_name}/predict', json=test_data) | |
first_prediction = response.json()[0]['target'] # Note: We only sent one prediction in the form of the `when` parameters, the array being returned will contain multiple predictions if more than one row/object is sent, the order of the predictions is the same as the ordering of the array being sent | |
predicted_value = first_prediction['predicted_value'] | |
confidence_percentage = round(100* first_prediction['confidence']) | |
print(f'Predicted a value of {predicted_value} with a confidence of {confidence_percentage}%') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment