Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.(5)

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

ITtutoria

ITtutoria Logo ITtutoria Logo

ITtutoria Navigation

  • Python
  • Java
  • Reactjs
  • JavaScript
  • R
  • PySpark
  • MYSQL
  • Pandas
  • QA
  • C++
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA
Home/ Questions/Error: unknown label type: 'continuous' - How to solve it?
Next
Answered
Ambre Parmentier
  • 30
Ambre Parmentier
Asked: May 12, 20222022-05-12T10:17:14+00:00 2022-05-12T10:17:14+00:00In: python

Error: unknown label type: ‘continuous’ – How to solve it?

  • 30

. Advertisement .

..3..

. Advertisement .

..4..

This is the program I run:

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))

After I run, it returns an error:

[email protected]:/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 <module>
  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'

Does anyone have any suggestions for the problem below: unknown label type: ‘continuous’ in the python- How to correct it?

continuous
  • 2 2 Answers
  • 188 Views
  • 0 Followers
  • 0
Answer
Share
  • Facebook
  • Report

2 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    lyytutoria Expert
    2022-06-02T11:08:37+00:00Added an answer on June 2, 2022 at 11:08 am

    The cause: This error happens because the floats are being passed to a classifier that requires the value parse type is the target vector.

    Solution: You can use scikit’s labelEncoder function to change your training scores. It is also true for your DecisionTree and KNeighbors qualifier.

    from sklearn import preprocessing 
    from sklearn import utils 
    lab_enc = preprocessing.LabelEncoder() 
    encoded = lab_enc.fit_transform(trainingScores) 
    >>> array([1, 3, 2, 0], dtype=int64) 
    print(utils.multiclass.type_of_target(trainingScores)) 
    >>> continuous 
    print(utils.multiclass.type_of_target(trainingScores.astype('int'))) 
    >>> multiclass 
    print(utils.multiclass.type_of_target(encoded)) 
    >>> multiclass
    • 14
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. Raphaël Perret
    2022-05-25T19:42:07+00:00Added an answer on May 25, 2022 at 7:42 pm

    LogisticRegression is for classification, not regression!

    The classification class must be specified in the Y variable.

    (0 and 1, for example)

    It is not the continuous variable.

    That would be a recalcitration problem.

    • 17
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

Sidebar

Ask A Question
  • How to Split String by space in C++
  • How To Convert A Pandas DataFrame Column To A List
  • How to Replace Multiple Characters in A String in Python?
  • How To Remove Special Characters From String Python

Explore

  • Home
  • Tutorial

Footer

ITtutoria

ITtutoria

This website is user friendly and will facilitate transferring knowledge. It would be useful for a self-initiated learning process.

@ ITTutoria Co Ltd.

Tutorial

  • Home
  • Python
  • Science
  • Java
  • JavaScript
  • Reactjs
  • Nodejs
  • Tools
  • QA

Legal Stuff

  • About Us
  • Terms of Use
  • Privacy Policy
  • Contact Us

DMCA.com Protection Status

Help

  • Knowledge Base
  • Support

Follow

© 2022 Ittutoria. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.