I have a dataset of cryptocurrency. I have features as ['Open', 'High', 'Low', 'Vol.', 'Change %'] and target variable as ['Price'].
I want to fit multiple regression even after converting the price column from string to float by using the code
df['Price'] = df['Price'].apply(lambda x: x.replace(',', '') if type(x) is str else x)
After that when I try to fit the model :
model = LinearRegression() model.fit(X, y)
It gives me value error as follows :
ValueError Traceback (most recent call last)
<ipython-input-23-ea6ca7c3c303> in <cell line: 3>()
1 # Fit a linear regression model to the data
2 model = LinearRegression()
----> 3 model.fit(X, y)
5 frames
/usr/local/lib/python3.10/dist-packages/pandas/core/generic.py in __array__(self, dtype)
2068
2069 def __array__(self, dtype: npt.DTypeLike | None = None) -> np.ndarray:
-> 2070 return np.asarray(self._values, dtype=dtype)
2071
2072 def __array_wrap__(
ValueError: could not convert string to float: '1,004.30'
Please help me in debugging. I am stuck here for long.
I tried with the code as
Convert the 'Price' column from strings to floats
df['Price'] = df['Price'].apply(lambda x: x.replace(',', '') if type(x) is str else x)
Fit a linear regression model to the data
model = LinearRegression() model.fit(X, y)