Logistic regression 逻辑回归系数

Logistic regression 逻辑回归系数,logistic-regression,statsmodels,Logistic Regression,Statsmodels,我需要一些逻辑回归方面的帮助。 以下是我的数据: ID | Mach_1 | Mach_2 | Mach_3 | Mach_4 | Mach_5 | ..Mach300 | Rejected Unit (%) | Yield(%) 127189.11 1 0 1 1 1 0 0.23 98.0% 178390.11 0 0

我需要一些逻辑回归方面的帮助。 以下是我的数据:

ID        | Mach_1  | Mach_2 | Mach_3  | Mach_4 | Mach_5 | ..Mach300 | Rejected Unit (%) | Yield(%)
127189.11     1         0        1         1        1          0            0.23             98.0%
178390.11     0         0        0         1        0          0            0.10             90.0%
902817.11     1         0        1         0        1          0            0.60             94.0%
DSK1201.11    1         0        0         0        1          0            0.02             99.98%
我有大约300马赫的Col和2K排。我想预测每台机器中,它对被拒绝单元的贡献百分比。我想知道哪台机器是被拒收的机器

我已经做了一些编码,但我面临一些错误,我不明白如何解决它。 下面是我的代码:

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import train_test_split

df = pd.read_csv('Data.csv')

#Convert ID into numerical
le = LabelEncoder()
labelencoder.fit_transform(df[:,0])

#Separate target variable and other columns
X = df.drop('Rejected Unit (%)',1)
y = df['Rejected Unit (%)']

#Split data into training and testing sets
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)
#Get the coefficient for each features column
import statsmodels.api as sm
model = sm.Logit(y_train,X_train)
res = mod.fit()
print(res.summary())
首先这是我的代码,然后我得到一个错误

ValueError: endog must be in the unit interval
然后我缩放我的y(目标变量),然后我得到另一个错误,我不知道为什么以及如何解决它

这是我缩放数据后的最新代码:

import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import train_test_split

df = pd.read_csv('Data.csv')

#Convert ID into numerical
le = LabelEncoder()
labelencoder.fit_transform(df[:,0])

#Separate target variable and other columns
X = df.drop('Rejected Unit (%)',1)
y = df['Rejected Unit (%)']

#scale target variable
from sklearn.preprocessing import MinMaxScaler
y_reshape = y.values.reshape(-1,1)
scaler = MinMaxScaler()
scaler.fit(y_reshape)
#change the numpy array of y_scale into dataframe
y = pd.DataFrame(y_scale)


#Split data into training and testing sets
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.25,random_state=0)
#Get the coefficient for each features column
import statsmodels.api as sm
model = sm.Logit(y_train,X_train)
res = mod.fit()
print(res.summary())
然后我得到了一个错误:


有人能帮我吗?

如果你的
拒绝单位(%)
是百分比,那么你只需要将它除以100就可以得到分数。第二个例外情况意味着你的
X\u序列很可能是单数。您可以使用
np.linalg.matrix\u rank(X\u train)
@Josef检查当我执行np.linalg.matrix(X\u train)时,输出显示291。这意味着它是奇异矩阵吗?如果291小于列数,那么它是奇异矩阵。在您提到的描述中,只有大约300列。@约瑟夫:是的,这些列只有300列。如何解决这个奇异矩阵问题,以便能够运行代码?