ngọc quỳnh trần
ngọc quỳnh trần

Reputation: 11

Unable to run linear regression

I am running the linear regression, however, i am having an error, which i can't fix. Please help me with this error. Thank you so much

import pandas as pd
import matplotlib.pyplot as plt
from sklearn import linear_model

data = pd.read_csv(r"C:\Users\quynh.tranngoc\Desktop\B32_DownloadTable_20230508_100440.csv")
print(data)

data.shape

data.plot(kind= 'scatter',x = 'total_order', y ='top_up_by_seller')
plt.show()

data.plot(kind='box')
plt.show()

data.corr()

order = pd.DataFrame(data['total_order'])
seller_top_up = pd.DataFrame(['top_up_by_seller'])
print(order)

lm = linear_model.LinearRegression()
model =lm.fit(order, seller_top_up)

The error I am having is

File ~\Desktop\untitled0.py:30 in <module>
    model =lm.fit(order, seller_top_up)

  File ~\Anaconda3\lib\site-packages\sklearn\linear_model\_base.py:662 in fit
    X, y = self._validate_data(

  File ~\Anaconda3\lib\site-packages\sklearn\base.py:581 in _validate_data
    X, y = check_X_y(X, y, **check_params)

  File ~\Anaconda3\lib\site-packages\sklearn\utils\validation.py:979 in check_X_y
    y = _check_y(y, multi_output=multi_output, y_numeric=y_numeric)

  File ~\Anaconda3\lib\site-packages\sklearn\utils\validation.py:997 in _check_y
    y = y.astype(np.float64)

ValueError: could not convert string to float: 'top_up_by_seller'

I wish i could fix my error

Upvotes: 0

Views: 56

Answers (0)

Related Questions