我已经包含了包含级别和薪水的数据集。想根据水平预测薪水 已创建特征X的矩阵,其中包括级别 和向量Y,其中包括预测价值的薪水。
from sklearn.tree import DecisionTreeRegressor
regressor=DecisionTreeRegressor(random_state=0)
regressor.fit(X,Y)
y_pred=regressor.predict(7)
y_pred=regressor.predict(7)
Traceback (most recent call last):
File "<ipython-input-10-1c954a5f3a7e>", line 1, in <module>
y_pred=regressor.predict(7)
File "C:\Users\Bhagwati\Anaconda3\lib\site- packages\sklearn\tree\tree.py", line 416, in predict
X = self._validate_X_predict(X, check_input)
File "C:\Users\Bhagwati\Anaconda3\lib\site-
packages\sklearn\tree\tree.py", line 377, in _validate_X_predict
X = check_array(X, dtype=DTYPE, accept_sparse="csr")
File "C:\Users\Bhagwati\Anaconda3\lib\site-
packages\sklearn\utils\validation.py", line 545, in check_array
"if it contains a single sample.".format(array))
ValueError: Expected 2D array, got scalar array instead:
array=7.0.
Reshape your data either using array.reshape(-1, 1) if your data has a
single feature or array.reshape(1, -1) if it contains a single sample.