I have imported pandas. On executing the dataframe, I got a value error in arrays. I’m new to Machine Learning, can any one help me with this issue?
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn.linear_model import LinearRegression
df = pd.read_csv(r'C:\Users\Apps\houseprices.csv')
%matplotlib inline
plt.xlabel('land (sqr ft)')
plt.ylabel('price (us$)')
plt.title('HOUSE PRICES')
plt.scatter(df.land, df.price, color = 'orange', marker = '+')
reg = LinearRegression()
reg.fit(df[['land']], df.price)
reg.predict(2200)
#returns
ValueError: Expected 2D array, got 1D array instead:
array=[2200].```
In reg.fit() you have mentioned
df[['land']]
reg.predict() should have same number of rows and columns as in df.
Try implementing the code below:
If the above code doesn’t work try this: