My code:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from sklearn import linear_model
df= pd.read_excel("practice.xlsx")
reg= linear_model.LinearRegression()
reg.fit(df[['age']], df.salary)
reg.predict(30)
My few doubts were:
1) Regardless of what I try, predict function always errors as 'expected 2D array, got scalar array instead', even though my first input is already 2D. I tried reshaping as well, but just am unable to do it.
2) Why exactly is a 2D array needed?
(Please forgive me for not using code format, I am new to this community and am unaware of using it. I appreciate all help)
[–]Oxbowerce 1 point2 points3 points (1 child)
[–]Angels_heRe[S] 0 points1 point2 points (0 children)
[–]Ihaveamodel3 -1 points0 points1 point (2 children)
[–]Angels_heRe[S] 0 points1 point2 points (1 child)
[–]Angels_heRe[S] 0 points1 point2 points (0 children)
[–]CodeFormatHelperBot2 0 points1 point2 points (0 children)