关于could not convert sting to float的问题(语言-python)

img

img

x是字符串,float(x)把字符串转换为浮点数,但是报错了。具体要看你输入了什麽,是不是含有cm字符啊

liner.predict(object)
其中object需要是一个np对象,你这里给了一个浮点数,所以导致他不能够正常工作,你需要给一个np的对象去才行
下面是一个线性预测小例子

# conding :utf-8 
 
from sklearn.linear_model import LogisticRegression 
import numpy as np 
x_train = np.array([[1,2,3], 
                    [1,3,4], 
                    [2,1,2], 
                    [4,5,6], 
                    [3,5,3], 
                    [1,7,2]]) 
   
y_train = np.array([3, 3, 3, 2, 2, 2]) 
   
x_test = np.array([[2,2,2], 
                   [3,2,6], 
                   [1,7,4]]) 
   
clf = LogisticRegression() 
clf.fit(x_train, y_train) 
   
# 返回预测标签 
print(clf.predict(x_test)) 
# [2 3 2] 
# 返回预测属于某标签的概率 
print(clf.predict_proba(x_test))