Skip to main content

A restful client library, designed to access predictnow restful API.

Project description

TO BEGIN ANY WORK WITH PREDICTNOW.AI CLIENT, WE START BY IMPORTING AND CREATING A CLASS INSTANCE

from predictnow.pdapi import PredictNowClient
import pandas as pd

api_key = "KeyProvidedToEachOfOurSubscriber"   
api_host = "http://%VMIP%"  

# Initial variables
username = "user1"  
email = "xxxx@gmail.com"
client = PredictNowClient(api_host,api_key)

YOU WILL NEED TO EDIT THIS INPUT DATASET FILE PATH, LABELNAME AND MODELNAME!

file_path = 'my_amazing_features.xlsx'  
labelname = 'futreturn' #might need to change this name accordingly 
modelname = 'model1' # 
import os

NOW YOUR PREDICTNOW.AI CLIENT HAS BEEN SETUP.

# For classification problem
params = {"timeseries": "yes", "weights": "no", "prob_calib": "no", "eda": "no", "type": "classification", "feature_selection": "shap", "analysis": "small", "boost": "gbdt", "mode": "train", "testsize": "1"}

# For regression problems
params = {"timeseries": "yes", "weights": "no", "prob_calib": "no", "eda": "no", "type": "regression", "feature_selection": "shap", "analysis": "small", "boost": "gbdt", "mode": "train", "testsize": "1"}

print("THE PARAMS", params)

LET'S CREATE THE MODEL BY SENDING THE PARAMETERS TO PREDICTNOW.AI

response = client.create_model
                   (
                    username=username, # only letters, numbers, or underscores
                    model_name=modelname,
                    params=params,
                   )

print(response)

LET'S LOAD UP THE FILE TO PANDAS IN THE LOCAL ENVIRONMENT

from pandas import read_csv  # If you have the Excel file, replace read_csv with read_excel
from pandas import read_excel
df = read_excel(file_path)  # Same here
df.name = "testdataframe"  # Optional, but recommended

print(df)

START TRAINING MODEL

NOTE: THIS MAY TAKE UP TO several minutes

response = client.train
                    (
                        model_name=modelname,
                        input_df=df,
                        label=labelname,
                        username=username,
                        email=email,
                        return_output=False
                    )

print("THE CLIENT HAS SENT THE DATASET TO THE SERVER AND TRIGGERED THE TRAINING MODEL TASK")
print(response)

CHECK THE STATUS OF THE MODEL

status = client.getstatus(
                            username=username,
                            train_id=response["train_id"]
                         )

print("Current status:")
print(status)

NOW WE WILL DOWNLOAD FILES

if status["state"] == "COMPLETED":

    response = client.getresult(
        model_name=modelname,
        username=username,
    )

    import pandas as pd
    predicted_prob_cv = pd.read_json(response.predicted_prob_cv)
    print("predicted_prob_cv")
    print(predicted_prob_cv)

    predicted_prob_test = pd.read_json(response.predicted_prob_test)
    print("predicted_prob_test")
    print(predicted_prob_test)


    predicted_targets_cv = pd.read_json(response.predicted_targets_cv)
    print("predicted_targets_cv")
    print(predicted_targets_cv)

START PREDICTING USING THE TRAINED MODEL

if status["state"] == "COMPLETED":

    df = read_excel("example_input_live_latest.xlsx")
    df.name = "myfirstpredictname"  # optional, but recommended

    # Predict demo
    response = client.predict(
        model_name=modelname,
        input_df=df,
        username=username,
        eda=params["eda"],
        prob_calib=params["prob_calib"]
    )

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pnow-0.0.1.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pnow-0.0.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file pnow-0.0.1.tar.gz.

File metadata

  • Download URL: pnow-0.0.1.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for pnow-0.0.1.tar.gz
Algorithm Hash digest
SHA256 c74a2629577629c4fa926719989b100c1bd2008f68b12e4a064802668e22dc17
MD5 6d5e6b26167cab64d45969269785b173
BLAKE2b-256 e19f5999124616735a1ca49a82b4411a3bdad000c5163d110438dbb696190f49

See more details on using hashes here.

File details

Details for the file pnow-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: pnow-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.6.4 pkginfo/1.7.1 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.7.9

File hashes

Hashes for pnow-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d301f7a17bca78d7e0cefefbad39d2e65c707c3497e6a382fa0e979dac72e853
MD5 3c2ecdbdceb05daa22aca41168ea3ec7
BLAKE2b-256 de8db83056c925405c967e6e5caa3887f3707b99a6b5e9f5c700ea12f9dace7b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page