logo
Loading...

使用logistic的multinomial出現Unknown label type: 'continuous'?錯誤 - Cupoy

# 使用logistic的multinomial# 切分訓練集/測試集x_train, x_test...

ml100-3,ml100-3-d38

使用logistic的multinomial出現Unknown label type: 'continuous'?錯誤

2019/11/01 09:55 AM
機器學習新手論壇
Ma Chao Ting
觀看數:0
回答數:1
收藏數:0
ml100-3
ml100-3-d38

# 使用logistic的multinomial

# 切分訓練集/測試集

x_train, x_test, y_train, y_test = train_test_split(X, D.target, test_size=0.1, random_state=4)


# 建立模型

logreg = linear_model.LogisticRegression(penalty='l2' ,C=1, multi_class='multinomial', solver='newton-cg')


# 訓練模型

logreg.fit(x_train, y_train)


# 預測測試集

y_pred = logreg.predict(x_test)


acc = accuracy_score(y_test, y_pred)

print("M-Accuracy: ", acc)


回傳:

ValueError: Unknown label type: 'continuous'



y_train的值為

array([22.3, 12.1, 28.6, 15.6, 19.2, 27.5, 32. , 20.2, 32.4, 18.4, 19.9,
      29.8, 20.1, 43.5, 24.5, 50. ,  7.2, 19.1, 21.2, 22.6, 22.9, 25. ,
      23.3, 17.3, 33. , 17.8, 23.8, 10.9, 18.6, 19.3, 16.7, 28. , 18.2,
      29.1, 11.9, 32.7, 18.3, 22.4, 45.4, 31.5, 48.5, 19.8, 41.7, 22.2,
      20.3, 20.7, 50. , 11.8, 19.5,  8.7, 23.3, 36.4, 13.3, 24.8, 20.4,
      44. , 29. , 39.8, 22.9, 23. , 15.3, 23.7, 30.5, 33.2, 26.4, 50. ,
      14.2,  8.1, 16. , 20. ,  8.5, 23.7, 26.4, 18.5, 20. , 50. , 13.4,
      13.1, 12.7, 50. , 15.6, 50. , 29.4, 42.8, 21.7, 11.8, 24.8, 19.4,
      17.5, 13.4, 13.9, 24.5, 15. , 13.8, 23.1, 12.5, 14.9, 21.9, 18.5,
      30.8, 14.6, 23.9, 18.2, 21.7, 13.5, 50. , 23.1, 48.8, 13.8, 20.1,
      50. , 34.9,  8.4, 15.2, 23. , 24.7, 25.3, 17.2, 50. , 22.9, 20.2,
      17.4, 19.5, 18.5, 14. , 22.6, 14.1, 15.6, 46. , 20.5, 13.5, 10.4,
      21.4, 21.6, 23.2, 23. , 17.6, 16.1,  5. ,  8.3, 27.5, 18.7, 21.7,
      30.7,  5. , 11.3,  7. , 32.9, 14.6, 12. , 28.1, 18. ,  5.6, 23.6,
      24.7, 22.5, 17.7, 13.1, 23.1, 25. , 14.9,  9.7, 22.8, 22. , 23.6,
      14.3, 18.8, 19.9, 13.6, 19.4, 16.8, 20. , 43.1, 27.9, 20.1, 19. ,
      19.2, 21.7, 33.1, 50. , 33.2, 20.1, 21.1,  8.8, 12.3, 14.5, 23.8,
      18.7, 21.8, 21.9, 21.7, 17.1, 23.1, 36.1, 28.2, 11.5, 19. , 22. ,
      10.5, 21.4, 16.5, 20.6, 23.3, 23.5, 15. , 26.5, 50. , 10.5, 17.5,
      13.6, 17.2, 19.1, 16.4, 20.6, 20.9, 30.1, 20.7, 22.2, 24.6, 25.2,
      37.9, 20.1, 29.6, 18.7, 23. , 22.9, 24.6, 24.8, 20.8, 22.4, 18.2,
      14.4, 23.2, 13. , 19.7, 21.2, 21.7, 24. , 22. , 20.6, 11.9, 24.3,
      23.8, 22.8, 13.3, 25. , 21. , 20.4, 33.1, 48.3, 14.5, 36. , 22.6,
      18.4, 18.9, 12.6, 15.2, 24.1, 29.9, 23.9, 31.6, 11.7, 20.3, 16.6,
      22.2, 26.6, 36.2, 28.4, 20.8, 15.4, 50. , 18.1, 23.1, 21.5, 13.1,
      21.8,  8.5, 15.6, 26.2, 32.2,  9.6, 31.6, 17.8, 34.7, 20. , 21. ,
      22.7, 28.7, 23.9, 35.4, 13.2, 18.3, 13.1, 23.1, 20.6,  7. , 13.4,
      24.1, 30.1, 20.3, 15.6, 26.6, 15. , 37.2, 27.1, 24.4, 17.8, 19.8,
      10.2, 23.1, 37.3, 23.2, 19.1, 19.6, 38.7, 25. , 23.7, 22.8, 16.2,
      20.3, 24.3, 21.2, 19.3, 20.6, 21.4, 14.4, 19.9, 16.2, 22.5, 19.1,
      17.8, 30.1, 14.8, 35.2, 29. , 25.1, 21.5,  8.3, 22. , 44.8, 24.5,
      34.9, 17.2, 33.8, 19.6, 14.1,  8.4, 33.3, 23.4, 21.4, 18.9, 21.2,
       7.2, 27.1, 14.5, 10.4, 21.4, 14.1, 10.2, 24.3, 18.6, 18.9, 10.9,
      24.4, 19.3, 25. , 36.5, 20.5, 20.4, 19.6, 27.9, 21.1, 26.6, 10.8,
      36.2, 34.9, 31.5, 31.7, 34.6, 17.8, 29.8, 35.1, 17.1, 13.4, 37. ,
      15.2, 27.5, 18.5, 19.6, 23.2, 32. , 23.4, 28.7, 22. , 13.8, 19.7,
      20.9, 17.1, 28.4, 43.8, 22.5, 50. , 50. , 33.4, 17.9, 25. , 22.3,
      50. ,  9.5, 10.2, 23.7, 23.8,  7.5, 23.9, 18.4, 20.4, 19.4, 17.4,
      12.7, 13.8, 22. , 29.1, 24.7, 20.8, 24.1, 15.4, 19.6, 32.5, 24. ,
       7.4, 25. , 15.7, 21.7, 21.2, 11.7, 22.7, 16.8, 21.6, 23.9, 22.1,
      20.6, 19.4, 22.6, 29.6, 23.3, 13.8, 33.4, 12.7, 22.2, 25. ,  7.2,
      30.3, 12.8, 22.6, 20.5])


在網上查到需要對y_train.as_type('int'),就可以正常執行

但是as int後值就會變成整數,不會是float了

請問為什麼有這個錯誤,以及該怎麼處理呢?