0
$\begingroup$

So i have training data like this:

x=[("feature1","feature2","feature3"), ("feature5","Feature9")]
y=("func1", "func7")

In which i turned to tuple due to errors about reshape your data. I was trying for hours without success using One Hot encoding, then moved to binary:

string to binary:

def category_to_num(x):
    mlb  = MultiLabelBinarizer()
    s=mlb.fit_transform(x)
    return s

training:

hot_en=category_to_num(x)
hot_eny=category_to_num(y)
X = hot_en
Y = hot_eny
clf = tree.DecisionTreeClassifier(criterion="gini" )
clf = clf.fit(X, Y)

Then given a test like t=["feature3","feature5","feature7"] (length always change),

num_text = tuple(t)
hot_en=category_to_num(num_text)
p=clf.predict(hot_en)

I keep getting errors like:

[[1 1 1 1 0 1 0 0 0 1 1 1 0]
 [1 1 0 1 1 0 1 1 1 0 0 1 1]]
X has 13 features, but DecisionTreeClassifier is expecting 18 features as input.

I have no idea where 13 feautes comes from, the test has 2. I do not udnerstand who has to be a tuple and (x? y? t?), and if working with a binarizer is good for DecisionTreeClassifier.

$\endgroup$
4
  • $\begingroup$ Welcome to DataScienceSE. This is quite messy and it's not very clear what you're trying to achieve. Why do you have tuples everywhere? This is not common at all and the learning algorithm cannot use them directly. Is there a meaningful reason to group variables this way, or is it only because you faced some technical problem without them? My impression is that you just want to predict two categorical target variables func1 and func7 using 5 categorical features in x. Is this correct? $\endgroup$
    – Erwan
    Feb 28, 2022 at 15:52
  • $\begingroup$ thanks a lot for trying to help, i made some progress and posted here another question about it, would be great if you look. datascience.stackexchange.com/questions/108622/… $\endgroup$
    – baltiturg
    Feb 28, 2022 at 15:57
  • $\begingroup$ Ok so you don't need an answer to this question anymore, right? $\endgroup$
    – Erwan
    Feb 28, 2022 at 16:46
  • $\begingroup$ yes expect that i still do not understand how checking frequency in a short sentence help, but thanks Erwan! $\endgroup$
    – baltiturg
    Mar 1, 2022 at 6:50

0