1

I have been conducting a learning algorithm using Decision Tree Classifier in Python.

from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(train, train_label)
predicted_label = clf.predict(test)

The Decision Tree Classifier accepts training labels from a large text file. I want to run the program without performing again the training process. How will I do it in Python? How will I include a precompiled learning model and used it for testing in another program? Is precompiled python files does have anything to do with it?

3
  • 1
    try pickle to save your model. Commented Mar 2, 2018 at 6:53
  • Thank you @MohamedThasinah . Put your comment in the answer section so that I can mark your answer as the correct answer. Commented Mar 2, 2018 at 7:06
  • Added to the solution :) Commented Mar 2, 2018 at 7:18

1 Answer 1

1

After training your model, you could save your model for future use for avoiding the process of training.

import pickle
model.fit(X,y)
saved_model = pickle.dump(model,open('saved_model.sav', 'wb'))#save your model
.
.
.

model = pickle.loads(open('saved_model.sav', 'rb'))#get your model from saved model file
model.predict(X[0:1])#use without training
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.