如何使用cross_val_score解决连续错误?

时间:2019-02-05 19:14:50

标签: python machine-learning scikit-learn random-forest

我对机器学习非常陌生,在过去的两天里,我一直在努力摆脱Unknown label type: 'continuous'错误。

我的代码:将numpy导入为np

import pandas as pd
from sklearn.model_selection import train_test_split  
from sklearn.preprocessing import StandardScaler  
from sklearn.ensemble import RandomForestClassifier  
from sklearn.model_selection import cross_val_score  

dataset = pd.read_csv(r'allData.csv', sep=',')  
X = dataset.iloc[:, 1:3].values  
y = dataset.iloc[:, 4].values  

train_features, test_features, train_lables, test_lables = train_test_split(X, y, test_size=10, random_state=10)  

feature_scaler = StandardScaler()  
train_features = feature_scaler.fit_transform(train_features)  
test_features = feature_scaler.transform(test_features)  

classifier = RandomForestClassifier(n_estimators=300, random_state=10)  
all_accuracies = cross_val_score(estimator=classifier, X=train_features, y=train_lables, cv="warn")  
#all_accuracies = cross_val_score(estimator=classifier, X=train_features, y=train_lables, cv=3)
#print(all_accuracies)  

该错误出现在cross_val_score部分,我不明白为什么会收到Unknown label type: 'continuous'错误。

任何帮助将不胜感激。


如果有帮助,我拥有的所有数据都是4列300行。

1 个答案:

答案 0 :(得分:0)

您在使用>>> datetime( 2018, 6, 1, 0, 0, 0, 0, tzlocal() ).astimezone( utc ) datetime.datetime(2018, 5, 31, 22, 0, tzinfo=<UTC>) 的同时具有连续输出。如果您要解决的问题是回归,则应使用RandomForestClassifier