Scikit-Learn Linear Regression, how to get the corresponding coefficients?

I try to make a function selection by evaluating the outputs of the regression coefficient and select the functions with the largest coefficients. The problem is that I do not know how to get the corresponding functions, since only coefficients from the coef._ attribute are returned. The documentation states:

Estimated coefficients for the linear regression problem. If several targets are transmitted during the fitting (y 2D), this is a 2D array (n_targets, n_features), and if only one target is transmitted, it is a 1D array of length n_features.

I go into my regression .fit (A, B), where A is a 2-D array, with the tfidf value for each function in the document. Example format:

"feature1" "feature2" "Doc1" .44 .22 "Doc2" .11 .6 "Doc3" .22 .2 

B are my target values ​​for data that are only 1-100 numbers associated with each document:

 "Doc1" 50 "Doc2" 11 "Doc3" 99 

Using regression.coef_, I get a list of coefficients, but not their corresponding functions! How can I get the functions? I assume that I need to modify the structure of my goals B, but I do not know how to do this.

+5
source share
3 answers

I suppose you are working on some sort of function selection task. Well, using regression.coef_ , it gets the appropriate coefficients for functions, i.e. regression.coef_[0] corresponds to "feature1", and regression.coef_[1] corresponds to "feature2". That should be what you want.

Well, I, in turn, recommend the sklearn tree model, which can also be used to select a function. To be specific, check out here .

+3
source
 coefficients = pd.DataFrame({"Feature":X.columns,"Coefficients":np.transpose(logistic.coef_)}) 
+2
source

What I found to work:

X = your independent variables

 coefficients = pd.concat([pd.DataFrame(X.columns),pd.DataFrame(np.transpose(logistic.coef_))], axis = 1) 

Suppose you specify: regression order. coef_ is the same as in the TRAIN set, remains true in my experience. (works with basic data, and also checks with correlations between X and y)

+1
source

Source: https://habr.com/ru/post/1206963/


All Articles