Search code examples
pythonscikit-learnsklearn-pandas

beginner question, using sklearn, saving model and test a single dataframe


New to python neural networks and sklearn, i wrote the following neural model. On a train set, it works nicely around 98% accuracy. Now i have some questions.

from sklearn.ensemble import GradientBoostingClassifier
model = GradientBoostingClassifier(learning_rate=0.99,max_depth=3)
model.fit(X_standardized, y)
predictions = model.predict(X_standardized)

from sklearn.metrics import confusion_matrix, classification_report
print(confusion_matrix(y, predictions))
print ()
print(classification_report(y,predictions))

Can the state of the neural network be saved and loaded.
ea store the weights gradients.

#something like:
Model.save("c:\neural\testnet.xml")

How to perform individual tests on a single data frame ea:

print ("answer =" ,Model.TestSample(test_data_frame))  # single input
   >>> answer = 0.78     ...estimated accuracy 97%  # or so

Solution

  • Regarding saving the state of the model: you can save the model using pickle package, e.g.:

    import pickle
    pickle.dump(model, open('model.sav', 'wb'))
    

    Not sure what you mean by 'individual tests on a single data frame', but if you want to test the model on some different (test) data, you can just create something like that:

    import sklearn
    df_predictions = model.predict( *input X data* )
    accuracy = sklearn.metrics.r2_score(*target (y data)*, df_predictions)