我从事一个根据输入的食物成分来预测美食的项目。但是输入是一个字符串,predict()需要一个稀疏矩阵。 我已经尝试过sparse.csr_matrix()和sparse.coo_matrix(),但是都无法正常工作,并且会生成错误“类型错误:类型不支持转换:(dtype('U28'),)“
s = df_ingredients.all_ingredients.values[0] //df_ingredients is the
//dataframe of the training dataset,
//all_ingredients is a column of
//df_ingredients having all the
//ingredients in a particular cuisine
n_array = np.array(s.split(';'))
s_matrix = sparse.csr_matrix(n_array) //This generates the Type Error
logistic.predict(s_matrix) //s_matrix is required here