ValueError:X每个示例有2个特性;应为10个

2024-10-04 03:27:06 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我是一个初学者在编码和做基因分析 为了我的生物信息学课。你知道吗

当我对一些基因进行分类时。我得到以下错误:

File "C:\Users\arthi\Anaconda3\lib\site-packages\sklearn\discriminant_analysis.py", line 514, in predict_proba
prob = self.decision_function(X)

File "C:\Users\arthi\Anaconda3\lib\site-packages\sklearn\linear_model\base.py", line 262, in decision_function
% (X.shape[1], n_features))

 ValueError: X has 2 features per sample; expecting 10

我使用了以下代码:

with open ('Genesdata.pkl', 'rb') as f:
datadict = pickle.load(f)
X_train =  datadict['X_train']
X_test = datadict['X_test']
y_train = datadict['y_train']
y_test = datadict['y_test']
Classifier =  LinearDiscriminantAnalysis()
pred = Classifier.predict(X_test)
acc = accuracy_score(y_test, pred)
error = 1 - acc
print(error)
plot_decision_boundary(X_test,pred,Classifier)`

这本词典是这样写的:' {'X_train':数组([[2.19006658,-0.73904548,1.0546373,…,2.66134771, 0.98862311, 0.44361308], [ 0.20861127, -0.93468434, 1.67651845, ..., 0.85252561, -1.09109426, 0.80392969], [ 1.42440021, -0.44252457, 0.44931581, ..., 2.24048554, 1.14914253, 0.99105977], ..., [-1.05716004, -1.05594894, 1.33725141, ..., 0.97913019, 3.47341899, -1.49987541], [-1.65004305, -0.94600641, 0.62179489, ..., 1.89665973, 3.23602037, 1.01596823], [-0.60023298, -0.578886 , -1.28959163, ..., 0.25218066, 2.59916467,-0.02751579]],“X_测试”:数组([[1.83955442,0.78721169,4.13619852,…,1.24837935, 0.81366998, 0.99879906], [ 2.37883518, 1.61882149, 1.38400345, ..., 0.80778427, -0.17820107, -0.82231867], [ 1.89283928, 3.3226534 , 3.51393647, ..., 1.77412229, -0.04522057, 0.45582996], ..., [ 0.46143703, 0.42804519, 0.34723485, ..., -1.0361394 , 0.5680955 , 0.74929476], [ 0.0964557 , -0.84329019, -0.98493767, ..., 0.94844 , -0.42561057, 1.92670305], [ 1.42933124, 1.72959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