Skip to main content

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

Project description

predictnow-api

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

predictnow-2.1.3.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

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

predictnow-2.1.3-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file predictnow-2.1.3.tar.gz.

File metadata

  • Download URL: predictnow-2.1.3.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/23.6.0

File hashes

Hashes for predictnow-2.1.3.tar.gz
Algorithm Hash digest
SHA256 ccba3e0d9a036a0ef60e47406e4fa5df1e8ccdd5834bc8ff5fa37542151664ec
MD5 899ff5463add8940a7fbdaec58b6b60c
BLAKE2b-256 ce0f31e67facbfbf18908eb8515e88c361290c49ab3f340be5fe1044fb7d847e

See more details on using hashes here.

File details

Details for the file predictnow-2.1.3-py3-none-any.whl.

File metadata

  • Download URL: predictnow-2.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.11.6 Darwin/23.6.0

File hashes

Hashes for predictnow-2.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 28ffbf24ddfb7b154cdf671ce6f52834ddca8ec69106274acf0906360048a104
MD5 56d24ba88f7d6d831e97d5f0c87a8848
BLAKE2b-256 52b031c163622b8a8375e4de08cb8b45eadc768363fb082b1c3eacbd0d7c6ec8

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