The threshold can be set using clf.predict_proba()
for example:
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier(random_state = 2)
clf.fit(X_train,y_train)
# y_pred = clf.predict(X_test) # default threshold is 0.5
y_pred = (clf.predict_proba(X_test)[:,1] >= 0.3).astype(bool) # set threshold as 0.3
More Related Contents:
- Save classifier to disk in scikit-learn
- How to get most informative features for scikit-learn classifiers?
- Scikit-learn: How to obtain True Positive, True Negative, False Positive and False Negative
- Mixing categorial and continuous data in Naive Bayes classifier using scikit-learn
- Multiclass Classification
- How to extract the decision rules from scikit-learn decision-tree?
- scikit-learn & statsmodels – which R-squared is correct?
- Accuracy Score ValueError: Can’t Handle mix of binary and continuous target
- Is it possible to specify your own distance function using scikit-learn K-Means Clustering?
- Use scikit-learn to classify into multiple categories
- How to get precision, recall and f-measure from confusion matrix in Python [duplicate]
- LabelEncoder for categorical features?
- Custom transformer for sklearn Pipeline that alters both X and y
- Save MinMaxScaler model in sklearn
- Scikit Learn OneHotEncoder fit and transform Error: ValueError: X has different shape than during fitting
- memory issues when transforming np.array using to_categorical
- confusion matrix error “Classification metrics can’t handle a mix of multilabel-indicator and multiclass targets”
- Can anyone explain me StandardScaler?
- What are the pros and cons between get_dummies (Pandas) and OneHotEncoder (Scikit-learn)?
- How to find the importance of the features for a logistic regression model?
- Scikit Learn GridSearchCV without cross validation (unsupervised learning)
- How to compute precision, recall, accuracy and f1-score for the multiclass case with scikit learn?
- scikit-learn: how to scale back the ‘y’ predicted result
- Save Naive Bayes Trained Classifier in NLTK
- Tensorflow Precision / Recall / F1 score and Confusion matrix
- Using Smote with Gridsearchcv in Scikit-learn
- Does GridSearchCV perform cross-validation?
- Model help using Scikit-learn when using GridSearch
- Does the SVM in sklearn support incremental (online) learning?
- Determining the most contributing features for SVM classifier in sklearn