2015-09-19 3 views
8

में त्रुटि का समर्थन नहीं किया गया है, मैं बस एक साधारण RandomForestRegressor उदाहरण करने की कोशिश कर रहा हूं। लेकिन सटीकता का परीक्षण करते समय मुझे यह त्रुटिलगातार याद किया गया है RandomForestRegressor

/Users/noppanit/anaconda/lib/python2.7/site-packages/sklearn/metrics/classification.pyc in accuracy_score(y_true, y_pred, normalize, sample_weight) 
    177 
    178  # Compute accuracy for each possible representation 
--> 179  y_type, y_true, y_pred = _check_targets(y_true, y_pred) 
    180  if y_type.startswith('multilabel'): 
    181   differing_labels = count_nonzero(y_true - y_pred, axis=1) 

/Users/noppanit/anaconda/lib/python2.7/site-packages/sklearn/metrics/classification.pyc in _check_targets(y_true, y_pred) 
    90  if (y_type not in ["binary", "multiclass", "multilabel-indicator", 
    91      "multilabel-sequences"]): 
---> 92   raise ValueError("{0} is not supported".format(y_type)) 
    93 
    94  if y_type in ["binary", "multiclass"]: 

ValueError: continuous is not supported 

यह डेटा का नमूना है। मैं असली डेटा नहीं दिखा सकता।

target, func_1, func_2, func_2, ... func_200 
float, float, float, float, ... float 

मेरा कोड यहां है।

import pandas as pd 
import numpy as np 
from sklearn.preprocessing import Imputer 
from sklearn.ensemble import RandomForestClassifier, RandomForestRegressor, ExtraTreesRegressor, GradientBoostingRegressor 
from sklearn.cross_validation import train_test_split 
from sklearn.metrics import accuracy_score 
from sklearn import tree 

train = pd.read_csv('data.txt', sep='\t') 

labels = train.target 
train.drop('target', axis=1, inplace=True) 
cat = ['cat'] 
train_cat = pd.get_dummies(train[cat]) 

train.drop(train[cat], axis=1, inplace=True) 
train = np.hstack((train, train_cat)) 

imp = Imputer(missing_values='NaN', strategy='mean', axis=0) 
imp.fit(train) 
train = imp.transform(train) 

x_train, x_test, y_train, y_test = train_test_split(train, labels.values, test_size = 0.2) 

clf = RandomForestRegressor(n_estimators=10) 

clf.fit(x_train, y_train) 
y_pred = clf.predict(x_test) 
accuracy_score(y_test, y_pred) # This is where I get the error. 

उत्तर

18

ऐसा इसलिए है क्योंकि accuracy_score केवल वर्गीकरण कार्यों के लिए है।

clf.score(X_test, y_test) 

कहाँ X_test नमूने है, y_test जमीनी सच्चाई मान संबंधित है: प्रतिगमन के लिए आप कुछ अलग, उदाहरण के लिए उपयोग करना चाहिए। यह भविष्यवाणियों की गणना करेगा।

+0

किसी को भी भविष्यवाणियों और प्रतिगमन के लिए वर्गीकरण की तरह परीक्षण मूल्यों की तुलना करने के लिए कैसे पता है? – Priyansh

1

चूंकि आप एक वर्गीकरण कार्य कर रहे हैं, तो आप मीट्रिक आर चुकता(दृढ़ संकल्प के सह कुशल) के बजाय सटीकता का उपयोग कर किया जाना चाहिए स्कोर(सटीकता स्कोर वर्गीकरण के लिए प्रयोग किया जाता है प्रयोजनों)।

किसी भी भ्रम मैं तुम्हें पंजीकरण/RFR की तरह अलग अलग चर नाम का उपयोग करने के लिए सुझाव से बचने के लिए।

आर चुकता score RandomForestRegressor द्वारा प्रदान की कार्यप्रणाली को कॉल करके गणना की जा सकती, उदाहरण के लिए:

rfr.score(X_test,Y_test) 
संबंधित मुद्दे