{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# German Credit Scoring Feed" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This notebook can be scheduled to provide a continuous flow of data to your German Credit Risk model. Paste your Watson Machine Learning credentials below, and verify that the value of the **DEPLOYMENT_NAME** variable matches the name of your deployed German Credit Risk model. You can also set the maximum and minimum number of records that will be scored per run." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install --upgrade watson-machine-learning-client --no-cache | tail -n 1" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "WML_CREDENTIALS = {\n", " \"PASTE HERE\"\n", "}" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "DEPLOYMENT_NAME = \"Spark German Risk Deployment - Final\"\n", "MIN_RECORDS = 30\n", "MAX_RECORDS = 200" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import json, random\n", "from watson_machine_learning_client import WatsonMachineLearningAPIClient" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wml_client = WatsonMachineLearningAPIClient(WML_CREDENTIALS)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "wml_deployments = wml_client.deployments.get_details()\n", "scoring_url = None\n", "for deployment in wml_deployments['resources']:\n", " if DEPLOYMENT_NAME == deployment['entity']['name']:\n", " scoring_url = deployment['entity']['scoring_url']\n", " break\n", " \n", "print(\"Scoring URL: {}\".format(scoring_url))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "try:\n", " with open('german_credit_feed.json', 'r') as scoring_file:\n", " scoring_data = json.load(scoring_file)\n", " print('file found')\n", " \n", "except:\n", " !wget https://raw.githubusercontent.com/emartensibm/german-credit/master/german_credit_feed.json\n", " with open('german_credit_feed.json', 'r') as scoring_file:\n", " scoring_data = json.load(scoring_file)\n", " print('file downloaded')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "fields = scoring_data['fields']\n", "values = []\n", "for _ in range(0, random.randint(MIN_RECORDS, MAX_RECORDS)):\n", " values.append(random.choice(scoring_data['values']))\n", "payload_scoring = {\"fields\": fields, \"values\": values}\n", "\n", "scoring_response = wml_client.deployments.score(scoring_url, payload_scoring)\n", "print(scoring_response)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3.5", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.5.5" } }, "nbformat": 4, "nbformat_minor": 1 }