python 3.x - Error while fitting a linear regression "ValueError: Found arrays with inconsistent numbers of samples" -
i trying execute following code:
import numpy np sklearn import linear_model class marketingcosts: def desired_marketing_expenditure(marketing_expenditure, units_sold, desired_units_sold): model = linear_model.linearregression() model.fit(units_sold, marketing_expenditure) output = model.predict(desired_units_sold) return output print(marketingcosts.desired_marketing_expenditure( [300000, 200000, 400000, 300000, 100000], [60000, 50000, 90000, 80000, 30000], 60000))
however, obtain following error when run it:
exec(code, run_globals) file "marketingcosts.py", in 60000)) file "marketingcosts.py", in desired_marketing_expenditure model.fit(units_sold, marketing_expenditure) valueerror: found arrays inconsistent numbers of samples: [1 5]
does know why happening? tried make model.fit using np.array argument throws similar error.
thanks in advance
this code works. need transpose data:
xtrain = np.array([[300000, 200000, 400000, 300000, 100000],]).t y = np.array([[60000, 50000, 90000, 80000, 30000],]).t xtest = np.array([[60000],]).t print(marketingcosts.desired_marketing_expenditure(y, xtrain, xtest))
i'v misplaced parameters, it's fixed. output 22000, looks good.
Comments
Post a Comment