python scikit-learn linear regressionを使って次の値を予測するコードが見つかりました。データの配列から予測する方法-python scikit learn pandas
私は単一のデータを予測することができますが、実際には6つの値を予測し、6つの値の予測を出力する必要があります。
predicted_value = {9,10,11,12,13,14,15}
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: '.format(result['intercept']))
print('Coefficient: '.format(result['coefficient']))
print('Predicted Value: '.format(result['predicted_value']))
print('Accuracy: '.format(result['accuracy']))
エラーメッセージは次のとおりです:
Traceback (most recent call last):
File "C:Python34\data\cp.py", line 28, in <module>
result = linear_model_main(X, Y, predicted_value)
File "C:Python34\data\cp.py", line 22, in linear_model_main
predict_outcome = regr.predict(predict_value)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 200, in predict return self._decision_function(X)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 183, in _decision_function
X = check_array(X, accept_sparse=['csr', 'csc', 'coo'])
File "C:\Python34\lib\site-packages\sklearn\utils\validation.py", line 393, in check_array array = array.astype(np.float64)
TypeError: float() argument must be a string or a number, not 'set'
C:\>
と
predicted_value = 9,10,11,12,13,14,15
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: '.format(result['intercept']))
print('Coefficient: '.format(result['coefficient']))
print('Predicted Value: '.format(result['predicted_value']))
print('Accuracy: '.format(result['accuracy']))
ここ
は、私がこのようにやってみましたコード
def linear_model_main(x_parameters, y_parameters, predict_value):
# Create linear regression object
regr = linear_model.LinearRegression()<
regr.fit(x_parameters, y_parameters)
# noinspection PyArgumentList
predict_outcome = regr.predict(predict_value)
score = regr.score(X, Y)
predictions = {'intercept': regr.intercept_, 'coefficient': regr.coef_, 'predicted_value': predict_outcome, 'accuracy' : score}
return predictions
predicted_value = 9 #I NEED TO PREDICT 9,10,11,12,13,14,15
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: {0}'.format(result['intercept']))
print('Coefficient: {0}'.format(result['coefficient']))
print('Predicted Value: {0}'.format(result['predicted_value']))
print('Accuracy: {0}'.format(result['accuracy']))
です
は、これらのエラー
C:\Python34\lib\site-packages\sklearn\utils\validation.py:386: DeprecationWarnin
g: Passing 1d arrays as data is deprecated in 0.17 and willraise 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)
Traceback (most recent call last):
File "C:Python34\data\cp.py", line 28, in <module>
result = linear_model_main(X, Y, predicted_value)
File "C:Python34\data\cp.py", line 22, in linear_model_main
predict_outcome = regr.predict(predict_value)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 200, in predict return self._decision_function(X)
File "C:\Python34\lib\site-packages\sklearn\linear_model\base.py", line 185, in _decision_function dense_output=True) + self.intercept_
File "C:\Python34\lib\site-packages\sklearn\utils\extmath.py", line 184, in safe_sparse_dot return fast_dot(a, b)
ValueError: shapes (1,3) and (1,1) not aligned: 3 (dim 1) != 1 (dim 0)
C:\>
を持って、私はこのような変更を加えた場合:
predicted_value = 9
result = linear_model_main(X, Y, predicted_value)
print('Constant Value: {1}'.format(result['intercept']))
print('Coefficient: {1}'.format(result['coefficient']))
print('Predicted Value: {}'.format(result['predicted_value']))
print('Accuracy: {1}'.format(result['accuracy']))
それが再び私はそれが限界を横切るというエラー得られます。何をする必要がありますか?
..私は単にそれは私に対応する値を予測する値9を与える場合 –
iは、エラーメッセージ –