0
$\begingroup$

quiet simple problem I would assume but I try it for the first time and no Version I find online works for me. I have a working Model and now I want to get the Coefficients for it. Which doesnt work. Here the Code I use:

#Father Data
X=data['Father'].values[:,None]
X.shape

#According sons data
y=data.iloc[:,1].values
y.shape

#Spliting the data into test and train data
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=0.2,random_state=0)

#Doing a linear regression
lm=LinearRegression()
lm.fit(X_train,y_train)

#Check the Impact each predictor has (in this example there is only one=Father)
cdf = pd.DataFrame(lm.coef_, X.columns, columns=['Coeff'])
print(cdf)

There erromessage reads:

cdf = pd.DataFrame(lm.coef_, X.columns, columns=['Coeff'])

AttributeError: 'numpy.ndarray' object has no attribute 'columns'

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.