简体   繁体   中英

How to use List as feature in scikit-learn

I'd like to use shape feature as a list in sklearn, is it possible? Using MLPClassifier

Given this input.

data=[{'forniture':1,'color':3, 'shape':[0.2,0.5,1.1]},
      {'forniture':2,'color':0, 'shape':[0.2,0.7,0.9]},
      {'forniture':2,'color':1, 'shape':[1.2,1.5,1.0]}]
pd.DataFrame(data)

Exit

   forniture  color            shape
0          1      3  [0.2, 0.5, 1.1]
1          2      0  [0.2, 0.7, 0.9]
2          2      1  [1.2, 1.5, 1.0]

When I pass shape as argument in clf.fit() :
TypeError: float() argument must be a string or a number, not 'list'

But I need the entire list, because it is the shape, I can not convert to scalar like Volume.

Any recomendation to fit with the shape and not volume?

Thanks, I really appreciate your help.

Upon reading the documentation here: https://scikit-learn.org/stable/modules/generated/sklearn.neural.network.MLPClassifier.html#sklearn.neural.network.MLPClassifier.fit It does not seem like it is possible to pass a list to the fit() function. Did you consider breaking up the list to three columns? If so it is explained here: Split a Pandas column of lists into multiple columns

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM