Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
340 views
in Technique[技术] by (71.8m points)

python - ValueError: bad input shape (560, 5) sklearn

I am starting to write the learnig machine model. I have a Y_train dataset containing the labels, there are 5 classes. The X_train dataset contains the samples. I try to make my model with the help of a logistic regression. shape : X_train ((560, 20531)) and Y_train ((560, 5)) have the same dimensions. I have seen a few publications associated with the same problem but I have not been able to solve the problem. I don't know how to correct this error,can you help me please ?

X = pd.read_csv('/Users/lottie/desktop/data.csv', header=None, skiprows=[0])
Y = pd.read_csv('/Users/lottie/desktop/labels.csv', header=None)

Y_encoded = list()
for i in Y.loc[0:,1] :
    if i == 'BRCA' : Y_encoded.append(0)
    if i == 'KIRC' : Y_encoded.append(1)
    if i == 'COAD' : Y_encoded.append(2)
    if i == 'LUAD' : Y_encoded.append(3)
    if i == 'PRAD' : Y_encoded.append(4)
Y_bis = to_categorical(Y_encoded)


#separation of the data
X_train, X_test, Y_train, Y_test = train_test_split(X, Y_bis, test_size=0.30, random_state=42)

regression_log = linear_model.LogisticRegression(multi_class='multinomial', solver='newton-cg')

X_train=X_train.iloc[:,1:]

#train model
train_train = regression_log.fit(X_train, Y_train)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

What exactly is your X_train exactly? It looks like at first glance that you're inverting your number of samples with your number of features.

Try X.shape and Y.shape and tell me what the console gives.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...