pandas - difference between np.linalg.lstsq and linear regression in scikit learn -


comb 1 pandas data frame following values.

yearid    teamid     salary         w
408         ana        51464167      82
409         ari       81027833      85

when use np.linalg.lstsq able print dfg data frame.

dfg = pd.dataframe()  comb1 = combined[combined['yearid'] == 2000] x1 = comb1['salary'].values /1000000  y1 =comb1['w'].values a1 = np.array([x1, np.ones(len(x1))]) w1 = np.linalg.lstsq(a1.t,y1)[0] yq = (w1[0]*x1+w1[1]) dfg['new val'] = y1 - yq 

when use scikit learn libary linear regression , same operation getting value error

from sklearn.linear_model import linearregression fg = pd.dataframe()  x2 = comb1['salary'].values /1000000  y2 =comb1['w'].values  x2_reshape = x2.reshape(-1,1) y2_reshape = y2.reshape(-1,1)  clf1 = linearregression() clf1.fit(x2_reshape, y2_reshape) predicted_train = clf1.predict(x2_reshape)   x_pre = y2 - predicted_train  fg['new val'] = x_pre 

what difference between these 2 ?? kindly me!!

they should same:

notes  implementation point of view, plain ordinary least squares (scipy.linalg.lstsq) wrapped predictor object. 

if getting error, it's because of way set data.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -