Skip to content

Instantly share code, notes, and snippets.

@amankharwal
Created October 8, 2020 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amankharwal/ec897f1811700a4bf7fb37d4494bb080 to your computer and use it in GitHub Desktop.
Save amankharwal/ec897f1811700a4bf7fb37d4494bb080 to your computer and use it in GitHub Desktop.
dt_clf = DecisionTreeClassifier() # Create Decision Tree classifer object
dt_clf = dt_clf.fit(X_train,y_train) # Fit/Train Decision Tree Classifer on training set
# Save model to file in the current working directory so that it can be imported and used.
# I use the pickle library to save the parameters of the trained model
pkl_file = "decision_tree_model.pkl"
with open(pkl_file, 'wb') as file:
pickle.dump(dt_clf, file)
# Load previously trained model from pickle file
with open(pkl_file, 'rb') as file:
dt_clf = pickle.load(file)
dt_clf # parameters of the Decision Tree model are shown below and can be further optimized to improve model performance
y_pred = dt_clf.predict(X_test) #Predict the response for test dataset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment