Last answered:

20 May 2024

Posted on:

20 May 2024

0

Error while using reg.fit(x,y)

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()

from sklearn.linear_model import LinearRegression

data = pd.read_csv("1.02. Multiple linear regression.csv")
data.head()

data.describe()

x = [['SAT','Rand 1,2,3']]
y = ['GPA']

reg = LinearRegression()

reg.fit(x,y)


I am getting the following error:


ValueError: dtype='numeric' is not compatible with arrays of bytes/strings.Convert your data to numeric values explicitly instead.

1 answers ( 0 marked as helpful)
Instructor
Posted on:

20 May 2024

0

Hi Subhrapratim!

Thanks for reaching out!

The error you encounter is because the variables x and y are not correctly defined and extracted from the dataframe. They need to be extracted as numerical data from the dataframe and not just as strings. 

So, instead of

x = [['SAT','Rand 1,2,3']]
y = ['GPA']

You need to use:

y = data ['GPA']
x = data [['SAT','Rand 1,2,3']]

Hope this helps.

Best,

Ivan

Submit an answer