简体   繁体   English

监督逻辑回归python

[英]supervised logistic regression python

i am tring to learn supervised learning in logistic regression from the http://www.dummies.com/programming/big-data/data-science/how-to-create-a-supervised-learning-model-with-logistic-regression/ 我正准备从http://www.dummies.com/programming/big-data/data-science/how-to-create-a-supervised-learning-model-with-logistic-中学习逻辑回归的监督学习。回归/
but i get this error TypeError: 'list' object is not callable 但我收到此错误TypeError:'list'对象不可调用
there are other error as well. 还有其他错误。 i've searched i came to know i've to use square brackets to access the list but that didnt worked. 我搜索了我才知道我必须使用方括号来访问列表,但这没有用。
can any one tell me what is wrong with code. 谁能告诉我代码有什么问题。 i am using anaconda(spyder 3.6) 我正在使用anaconda(spyder 3.6)

here is my code 这是我的代码

from sklearn.datasets import load_iris
from sklearn import linear_model
from sklearn import cross_validation
from sklearn import metrics

iris = load_iris()
X_train, X_test, y_train, y_test=cross_validation.train_test_split(iris.data,iris.target,test_size=0.10,random_state=111)
logClassifier = linear_model.LogisticRegression(random_state=111)
logClassifier.fit(X_train, y_train)
predicted = logClassifier.predict(X_test)
predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2])
y_testarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2])
metrics.accuracy_score(y_test, predicted)   
predicted == y_testarray([ True, True, True, True, True, True, True,  True,True, True, True, True, True, True,  True], dtype=bool)

in the link you provided, it looks like some of the lines are input and some lines are output (which is not made very clear), and so not all the lines are actual code but also contain output of what would happen if you ran the code 在您提供的链接中,看起来有些行是输入的,有些行是输出的(这不是很清楚),因此并非所有的行都是实际的代码,但是还包含如果您运行码

to clarify, the line 澄清一下

predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2]) is the ouput of the line predicted = logClassifier.predict(X_test) which is shown to illustrate the ouput of the predict function, but the line predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2]) itself is output and should not be added to the code predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2]) predicted = logClassifier.predict(X_test) predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2])predicted = logClassifier.predict(X_test)行的输出predicted = logClassifier.predict(X_test)其中所示为说明预测函数的输出,但行predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2]) 0,0,2,2,1,1,0,0,2,2,1,1,2,0,2,2,2 predictedarray=([0, 0, 2, 2, 1, 0, 0, 2, 2, 1, 2, 0, 2, 2, 2])本身是输出,不应添加到代码中

the same goes for the last line : predicted == y_testarray([ True, True, True, True, True, True, True, True,True, True, True, True, True, True, True], dtype=bool) 最后一行也是如此: predicted == y_testarray([ True, True, True, True, True, True, True, True,True, True, True, True, True, True, True], dtype=bool)

although in the link it is not made clear in the link, I think this is to show that the results of running 尽管在链接中没有明确说明,但我认为这是为了表明运行结果

predicted == y_testarray would be equal to an array containing only True as the two arrays are indeed the same, so you also don't need this last line predicted == y_testarray等于仅包含True的数组,因为这两个数组确实相同,因此您也不需要最后一行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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