public class ScikitLearnRegression extends BaseRegression implements ExternalModel
fit(X, y)
: Train the model given attribute matrix X,
and observation matrix y.
predict(X)
: Run the model
Note: This implementation requires the ability to write temporary
files on whatever system Magpie is running on.
Usage: <model> [<compression level>]
See
this tutorial for how to save Scikit-Learn objects.
Modifier and Type | Field and Description |
---|---|
boolean |
Debug
Whether to print output from python stdout to screen
|
protected java.lang.Process |
ScikitServer
Scikit server process
|
AttributeSelector, trained, TrainingStats, validated, ValidationStats
Constructor and Description |
---|
ScikitLearnRegression() |
Modifier and Type | Method and Description |
---|---|
ScikitLearnRegression |
clone() |
void |
close() |
void |
closeServer()
Set a command to the model server that we are done with it.
|
int |
getNFittingParameters()
Number of fitting parameters in a model.
|
int |
getPort()
Get the port number for this model's server
|
java.lang.Process |
getProcess()
Get the process holding this external port
|
protected java.lang.String |
printModel_protected()
Internal method that handles printing the model as a string.
|
java.util.List<java.lang.String> |
printModelDescriptionDetails(boolean htmlFormat)
Print details of the model.
|
java.lang.String |
printUsage()
Print out required format for options.
|
void |
readModel(java.io.InputStream input)
Read model from an input stream
|
void |
run_protected(Dataset runData)
Run a model without checking if stuff is trained (use carefully)
|
boolean |
serverIsRunning()
Check whether the server is running
|
void |
setCompressionLevel(int level)
Define how well model is compressed after training.
|
void |
setOptions(java.util.List<java.lang.Object> Options)
Set any options for this object.
|
void |
startServer()
Start the server hosting the model.
|
protected void |
train_protected(Dataset TrainData)
Train a model without evaluating performance
|
void |
writeModel(java.io.OutputStream output)
Write model to output stream
|
doRobustRegression, getRobustRegressionQ, robustTraining, runCommand, setRobustRegressionQ
about, crossValidate, crossValidate, crossValidate, done, externallyValidate, getAttributeSelector, getCitations, getFilter, getTrainTime, getValidationMethod, handleSetCommand, isTrained, isValidated, loadState, printCommand, printDescription, printModel, resetModel, run, saveCommand, saveState, setAttributeSelector, setComponent, setFilter, train, train
protected transient java.lang.Process ScikitServer
public boolean Debug
public void close() throws java.lang.Exception
close
in interface java.lang.AutoCloseable
java.lang.Exception
public void closeServer()
ExternalModel
closeServer
in interface ExternalModel
public ScikitLearnRegression clone()
clone
in class BaseRegression
public void setOptions(java.util.List<java.lang.Object> Options) throws java.lang.Exception
Options
setOptions
in interface Options
Options
- Array of options as Objects - can be null
java.lang.Exception
- if problem with inputspublic java.lang.String printUsage()
Options
printUsage
in interface Options
public int getPort()
ExternalModel
getPort
in interface ExternalModel
public void setCompressionLevel(int level) throws java.lang.Exception
This class works by launching a server than runs a scikit-learn model. After training, this server sends back the model as a pickle file. For large datasets, this could be a huge file. This option allows one to compress it before transmission.
setCompressionLevel
in interface ExternalModel
level
- Desired level. 1: Fastest, 9: Smallest memory footprintjava.lang.Exception
ScikitModel
public void readModel(java.io.InputStream input) throws java.lang.Exception
readModel
in interface ExternalModel
input
- Input stream providing model datajava.io.IOException
java.lang.Exception
public void writeModel(java.io.OutputStream output) throws java.io.IOException
writeModel
in interface ExternalModel
output
- java.io.IOException
public void startServer() throws java.lang.Exception
ExternalModel
startServer
in interface ExternalModel
java.lang.Exception
public boolean serverIsRunning()
ExternalModel
serverIsRunning
in interface ExternalModel
public java.lang.Process getProcess()
ExternalModel
getProcess
in interface ExternalModel
protected void train_protected(Dataset TrainData)
BaseModel
train_protected
in class BaseModel
TrainData
- Training datapublic void run_protected(Dataset runData)
BaseModel
run_protected
in class BaseModel
runData
- Training dataprotected java.lang.String printModel_protected()
BaseModel
printModel_protected
in class BaseModel
public int getNFittingParameters()
AbstractRegressionModel
getNFittingParameters
in interface AbstractRegressionModel
public java.util.List<java.lang.String> printModelDescriptionDetails(boolean htmlFormat)
BaseModel
BaseModel.printDescription(boolean)
.
Implementation note: No not add indentation for details. That is handled
by BaseModel.printDescription(boolean)
. You should also call the super
operation to get the Normalizer and Attribute selector settings
printModelDescriptionDetails
in class BaseModel
htmlFormat
- Whether to use HTML format