import pandas as pd import numpy as np from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression import pickle import tabpy_client # Connect to TabPy server using the client library connection = tabpy_client.Client('http://localhost:9004/') # load the model from disk def tableau_classifier(arg2,arg3,arg4,arg5,arg6,arg7,arg8,arg9): inputs_df = pd.DataFrame( { 'Perf-Low': arg2, 'Perf-Mid': arg3, 'Perf-Mid-High': arg4, 'Perf-Undet': arg5, 'Ven-Low': arg6, 'Ven-Mid': arg7, 'Ven-Mid-High': arg8, 'Ven-Undet': arg9 } ) loaded_model = pickle.load(open('/Users/arturoroman/Desktop/Udemy/lr_model.sav', 'rb')) return loaded_model.predict(inputs_df).tolist() # Publish the tableau_classifier function to TabPy server so it can be used from Tableau # Using the name DiagnosticsDemo and a short description of what it does connection.deploy('EventCalssifier',
import tabpy_client from tabpy.tabpy_tools.client import Client client = tabpy_client.Client('http://localhost:9004/') def fraud_predictor5(_arg1, _arg2, _arg3): import pandas as pd row = { 'shipping': _arg1, 'shipping scheduled': _arg2, 'country_str': _arg3 } #Convert it into a dataframe test_data = pd.DataFrame(data=row, index=[0]) from sklearn import preprocessing le = preprocessing.LabelEncoder() test_data['country_str'] = le.fit_transform(test_data['country_str']) #Predict the Fraud predprob_survival = random_forest.predict_proba(test_data) #Return only the probability return [probability[1] for probability in predprob_survival] def late_delivery(_arg1, _arg2): import pandas as pd row = {'shipping scheduled': _arg1, 'country_str': _arg2} #Convert it into a dataframe test_data = pd.DataFrame(data=row, index=[0]) from sklearn import preprocessing le = preprocessing.LabelEncoder() test_data['country_str'] = le.fit_transform(test_data['country_str'])
import tabpy_client client = tabpy_client.Client('http://127.0.0.1:9004') def external_services_say_hello(message, service): import requests if service == 'PYTHON': r = requests.post('http://127.0.0.1:5000/python_says_hello', data={'message': message}) elif service == 'R': r = requests.post('http://127.0.0.1:6313/r_says_hello', data={ 'message': message, }) serviceResult = r.json() return serviceResult['result'] client.deploy('external_services_say_hello', external_services_say_hello, 'Make Python or R say Hello or anything you want.', override=True) print('*** Model deployed successfully ***')
import Algorithmia import tabpy_client ALGORITHMIA_API_KEY = 'YOUR_API_KEY' #algorithmia.com/user#credentials TABPY_SERVER_URL = 'http://localhost:9004/' DEBUG = True def algorithmia(algorithm_name, input): if DEBUG: print("algorithm: %sinput: %s\n" % (algorithm_name, input)) try: client = Algorithmia.client(ALGORITHMIA_API_KEY) algo = client.algo(algorithm_name) result = algo.pipe(input).result except Exception as x: if DEBUG: print(x) raise Exception(str(x)) if DEBUG: print("result: %s" % result) return result tabpy_conn = tabpy_client.Client(TABPY_SERVER_URL) tabpy_conn.deploy( 'algorithmia', algorithmia, 'Run a function on Algorithmia: algorithmia(algorithm_name, input)', override=True)