我是靠谱客的博主 坦率芹菜,最近开发中收集的这篇文章主要介绍python logistic 多标签_LogisticRegression:未知标签类型:在python中使用sklearn’连续’...,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

我有以下代码来测试一些最流行的sklearn python库的ML算法:

import numpy as np

from sklearn import metrics, svm

from sklearn.linear_model import LinearRegression

from sklearn.linear_model import LogisticRegression

from sklearn.tree import DecisionTreeClassifier

from sklearn.neighbors import KNeighborsClassifier

from sklearn.discriminant_analysis import LinearDiscriminantAnalysis

from sklearn.naive_bayes import GaussianNB

from sklearn.svm import SVC

trainingData = np.array([ [2.3, 4.3, 2.5], [1.3, 5.2, 5.2], [3.3, 2.9, 0.8], [3.1, 4.3, 4.0] ])

trainingScores = np.array( [3.4, 7.5, 4.5, 1.6] )

predictionData = np.array([ [2.5, 2.4, 2.7], [2.7, 3.2, 1.2] ])

clf = LinearRegression()

clf.fit(trainingData, trainingScores)

print("LinearRegression")

print(clf.predict(predictionData))

clf = svm.SVR()

clf.fit(trainingData, trainingScores)

print("SVR")

print(clf.predict(predictionData))

clf = LogisticRegression()

clf.fit(trainingData, trainingScores)

print("LogisticRegression")

print(clf.predict(predictionData))

clf = DecisionTreeClassifier()

clf.fit(trainingData, trainingScores)

print("DecisionTreeClassifier")

print(clf.predict(predictionData))

clf = KNeighborsClassifier()

clf.fit(trainingData, trainingScores)

print("KNeighborsClassifier")

print(clf.predict(predictionData))

clf = LinearDiscriminantAnalysis()

clf.fit(trainingData, trainingScores)

print("LinearDiscriminantAnalysis")

print(clf.predict(predictionData))

clf = GaussianNB()

clf.fit(trainingData, trainingScores)

print("GaussianNB")

print(clf.predict(predictionData))

clf = SVC()

clf.fit(trainingData, trainingScores)

print("SVC")

print(clf.predict(predictionData))

前两个工作正常,但我在LogisticRegression调用中遇到以下错误:

root@ubupc1:/home/ouhma# python stack.py

LinearRegression

[ 15.72023529 6.46666667]

SVR

[ 3.95570063 4.23426243]

Traceback (most recent call last):

File "stack.py", line 28, in

clf.fit(trainingData, trainingScores)

File "/usr/local/lib/python2.7/dist-packages/sklearn/linear_model/logistic.py", line 1174, in fit

check_classification_targets(y)

File "/usr/local/lib/python2.7/dist-packages/sklearn/utils/multiclass.py", line 172, in check_classification_targets

raise ValueError("Unknown label type: %r" % y_type)

ValueError: Unknown label type: 'continuous'

输入数据与之前的调用相同,那么这里发生了什么?

顺便说一句,为什么在LinearRegression()和SVR()算法的第一次预测中存在巨大的差异(15.72对3.95)?

最后

以上就是坦率芹菜为你收集整理的python logistic 多标签_LogisticRegression:未知标签类型:在python中使用sklearn’连续’...的全部内容,希望文章能够帮你解决python logistic 多标签_LogisticRegression:未知标签类型:在python中使用sklearn’连续’...所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(44)

评论列表共有 0 条评论

立即
投稿
返回
顶部