————————————————————————— ValueError Traceback (most recent call last) /tmp/ipykernel_3283197/857401802.py in ?() —> 43 import pandas as pd 44 from sklearn.model_selection import train_test_split 45 from sklearn.ensemble import RandomForestRegressor 46 from sklearn.metrics import mean_squared_error /home/share/temp/venv/lib/python3.8/site-packages/sklearn/ensemble/_forest.py in ?(self, X) 980 The predicted values. 981 “”” 982 check_is_fitted(self) 983 # Check data –> 984 X = self._validate_X_predict(X) 985 986 # Assign chunk of trees to jobs 987 n_jobs, _, _ = _partition_estimators(self.n_estimators, self.n_jobs) /home/share/temp/venv/lib/python3.8/site-packages/sklearn/ensemble/_forest.py in ?(self, X) 595 def _validate_X_predict(self, X): 596 “”” 597 Validate X whenever one tries to predict, apply, predict_proba.””” 598 check_is_fitted(self) –> 599 X = self._validate_data(X, dtype=DTYPE, accept_sparse=”csr”, reset=False) 600 if issparse(X) and (X.indices.dtype != np.intc or X.indptr.dtype != np.intc): … 1999 if ( 2000 astype_is_view(values.dtype, arr.dtype) 2001 and using_copy_on_write() ValueError: could not convert string to float: ‘来月の金額’
エラーは、特徴量に文字列が含まれているために、モデルの予測時に数値に変換できないことが原因です。具体的には、"来月の金額"や"来月の原価"などの文字列が含まれています。
予測に使用するデータフレームが、モデルのトレーニング時と同じ形式でなければなりません。つまり、予測に使用するデータフレームには文字列ではなく数値が含まれている必要があります。
予測に使用するデータフレームの準備の部分で、"来月の金額"などの文字列を実際の数値に置き換える必要があります。この部分を修正して、再度予測を行ってください。

ディスカッション
コメント一覧
まだ、コメントがありません