2017-09-30 52 views
0

緊隨着scikit-learn文檔,我正在試圖安裝一個虛擬classif9er。但是,在運行時會引發錯誤值。這是意想不到的,因爲之前我使用的是相同的數據:X = vector_data(一個稀疏矩陣),y = vector_target(一個int列表)與網格搜索cv擬合,沒有這樣的錯誤。Sklearn train_test_split創建1d數組

因此它必須引入train_test_split。

爲什麼在我的代碼中發生這種情況,而不是文檔,應該採取哪些預防措施?

X_train, X_test, y_train, y_test = train_test_split(vector_data, vector_target, random_state=0) 
clf = DummyClassifier(strategy='stratified',random_state=0) 
clf.fit(X_train, y_train) 
clf.score(X_test,y_test) 

DeprecationWarning: Passing 1d arrays as data is deprecated in 0.17 and will raise ValueError in 0.19. 
Reshape your data either using X.reshape(-1, 1) if your data has a single feature or X.reshape(1, -1) if it contains a single sample. 
     DeprecationWarning) 
+0

什麼是'vector_data.shape','X_train.shape'和'X_test.shape'? – Psidom

回答

0

首先,永遠,永遠,閱讀警告/錯誤信息。

因此,嘗試這樣的事情:

X_train, X_test, y_train, y_test = train_test_split(vector_data.reshape(-1, 1), 
      vector_target, random_state=0) 

我不能多說,只是試圖理解這個簡單的代碼。