숫자 데이터 (부동 소수점)에 몇 가지 기본적인 기계 학습 알고리즘을 실행하려고하고 데이터를 읽는 데 문제가 있습니다. 나는 python 2.7, sklearn, pandas를 사용하고 jupyter (ipython notebook)를 통해 작업했다. 첫 번째 패스에서 기본적인 임의의 포리스트 검색을 사용하려고했지만 기능을 사용할 때 ValueError를 계속 사용합니다. Sklearn 팬더의 데이터 프레임 데이터를 사용하여 값 오류를 피할 수있는 방법을 찾을 수 없습니다.
데이터
는df = pd.read_table("p12.dat", delim_whitespace=True)
df.dtypes 관심의 모든 값을 float64 것을 나타내는 dataframe로 판독 하였다.
기본 식 사용 :
def classification_model(model, data, predictors, outcome):
model.fit(data[predictors],data[outcome])
predictions = model.predict(data[predictors])
accuracy = metrics.accuracy_score(predictions,data[outcome])
print "Accuracy : %s" % "{0:.3%}".format(accuracy)
print "Cross-Validation Score : %s" % "{0:.3%}".format(np.mean(error))
model.fit(data[predictors],data[outcome])
을 다음 변수를 설정하고, 실행 : I가 탐색 및 검색 좀
ValueError Traceback (most recent call last)
<ipython-input-9-7dd611cce611> in <module>()
----> 1 classification_model(model, df,predictor_var,outcome_var)
<ipython-input-8-956e572db2f4> in classification_model(model, data, predictors, outcome)
1 def classification_model(model, data, predictors, outcome):
2 #Fit the model:
----> 3 model.fit(data[predictors],data[outcome].values)
4
5 #Make predictions on training set:
/Users/jonathangough/anaconda/lib/python2.7/site-packages/sklearn/ensemble/forest.pyc in fit(self, X, y, sample_weight)
233 self.n_outputs_ = y.shape[1]
234
--> 235 y, expanded_class_weight = self._validate_y_class_weight(y)
236
237 if getattr(y, "dtype", None) != DOUBLE or not y.flags.contiguous:
/Users/jonathangough/anaconda/lib/python2.7/site-packages/sklearn/ensemble/forest.pyc in _validate_y_class_weight(self, y)
419
420 def _validate_y_class_weight(self, y):
--> 421 check_classification_targets(y)
422
423 y = np.copy(y)
/Users/jonathangough/anaconda/lib/python2.7/site-packages/sklearn/utils/multiclass.pyc in check_classification_targets(y)
171 if y_type not in ['binary', 'multiclass', 'multiclass-multioutput',
172 'multilabel-indicator', 'multilabel-sequences']:
--> 173 raise ValueError("Unknown label type: %r" % y)
174
175
ValueError: Unknown label type: array([[ 2.72000000e+00],
[ 4.60000000e+00],
[ 6.70000000e+00],
[ 2.30000000e+00],
[ 1.70000000e+00],
[ 2.20000000e+00],
[ 3.60000000e+00],
[ 9.10000000e+00],
하지만 I :
outcome_var = 'ki'
predictor_var = ['Etot','TSs','Eww-nbr']
model = RandomForestClassifier(n_estimators=100)
classification_model(model, df,predictor_var,outcome_var)
에러 것은 무엇을 해야할지 알 수 없습니다. 내 이해는 하나의 임의의 포리 스트 알고리즘 (그래서 내가 그 오류라고 생각하지 않았다)에서 수레를 사용할 수 있었다.
어떤 통찰력도 인정 될 것입니다.
sklearn 모델의 입력으로 팬더의 밑에있는 numpy 배열을 사용해 볼 수 있습니다. 귀하의 코드에서 데이터 [예측 자], 데이터 [결과]에 대한 .values가없는 것을 볼 수 있습니다. 반면 스택 트레이스에서는 데이터 [결과]. 값이 있습니다. 모든 입력에 '.values'가 있는지 확인하십시오. – DataSwede