Home > Back-end >  How to weight observations in decision tree python
How to weight observations in decision tree python

Time:06-10

I have a data set with policies that run for different numbers of days. The policies that run for more days have to have higher weight compared to the policies that run for less days. Is there a way that I can do that in tree based models in python? Especially, decision tree model.

Every policy is 1 row.

Thanks,

CodePudding user response:

You can use the sample_weight argument of the fit() function to weight your training samples.

As follow:

from sklearn.tree import DecisionTreeClassifier
from sklearn.datasets import make_classification

X, y = make_classification()
weights = np.random.uniform(size=y.shape)

DecisionTreeClassifier().fit(X, y, sample_weight=weights)
  • Related