Python Forum
How to use a pmml model in Python
Thread Rating:
  • 2 Vote(s) - 2.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to use a pmml model in Python
#1
Hey, I have a small neural network model, 25 neurons, that I trained recently, that I want to use to scan executable files with, to determine if they're safe or not. I transferred the model from R to pmml, and I already made a small code to scan executable files and extract system calls with, which I then turn into 0/1 vectors. My question is, how do I input these vectors into the pmml model, and how do I get them to give me a simple yes/no result?
Reply
#2
Hello

Did you save the learning in .json,.h5, .npy ? Sorry no clue exactly how it looks - and I have not worked on pmml models. But below is what might help you or point you to correct direction.

from keras.models import model_from_json
from sklearn.preprocessing import LabelEncoder
import pandas as pd
import numpy as np

load_file = open('model.json', "r")
loaded_model_json = load_file.read()
load_file.close()

loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights("model.h5")

encoder = LabelEncoder()
encoder.classes_ = np.load('encoded_classes.npy')

...
...
...
...

#Usually models take numpy not dataframes
X_input_cat = np.asarray(X_input_cat)
pred = loaded_model.predict_classes(X_input_cat[:,:])
Reply
#3
(Aug-05-2017, 05:10 AM)radioactive9 Wrote: Hello

Did you save the learning in .json,.h5, .npy ? Sorry no clue exactly how it looks - and I have not worked on pmml models. But below is what might help you or point you to correct direction.

from keras.models import model_from_json
from sklearn.preprocessing import LabelEncoder
import pandas as pd
import numpy as np

load_file = open('model.json', "r")
loaded_model_json = load_file.read()
load_file.close()

loaded_model = model_from_json(loaded_model_json)
loaded_model.load_weights("model.h5")

encoder = LabelEncoder()
encoder.classes_ = np.load('encoded_classes.npy')

...
...
...
...

#Usually models take numpy not dataframes
X_input_cat = np.asarray(X_input_cat)
pred = loaded_model.predict_classes(X_input_cat[:,:])

I haven't saved anything save for a pmml file. The model was already trained in R, and once I trained it I exported it to pmml so that I can try using it in Python. I'm just curious as to how to open the model, run my data through it, and get an output.
Reply
#4
Hello

Tried to look around. Though I have never worked on PMML and very new to this area of study - but found a github link

May be this helps

https://github.com/ctrl-alt-d/lightpmmlpredictor
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  LDA Model prepare() method failure in Python noerkes 0 244 Feb-22-2024, 01:42 PM
Last Post: noerkes
  How to run a linear model by group in Python? Betty775522 0 515 Oct-18-2023, 07:09 PM
Last Post: Betty775522
  issue displaying summary of whole keras CNN model on TensorFlow with python Afrodizzyjack 0 1,621 Oct-27-2021, 04:07 PM
Last Post: Afrodizzyjack
  arima model error in python wissam1974 0 4,179 Jan-23-2019, 09:37 AM
Last Post: wissam1974

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020