Python:sklearn单独测试一个数据 的报错处理:ValueError: Expected 2D array, got 1D array instead:

import numpy as np
import pandas as pd
from copy import deepcopy
from sklearn import datasets
from scipy.spatial.distance import pdist, squareform
from sklearn.model_selection import train_test_split
from collections import OrderedDict
from itertools import combinations, product
from sklearn.linear_model import LogisticRegression
from sklearn.svm import SVC
from sklearn.metrics import accuracy_score, f1_score
from itertools import combinations, product
from sklearn.model_selection import StratifiedKFold


X,y = datasets.load_iris(return_X_y=True)
X_train,X_test,y_train,y_test = train_test_split(X,y,test_size=0.2,random_state=0)

model = LogisticRegression(solver='newton-cg', penalty='l2')
model.fit(X_train,y_train)



y_pred = model.predict_proba(np.array(X_test[5]).reshape(1, -1))
print(y_pred)
y_pred = model.predict_proba(X_test[[5]])
print(y_pred[0])

 

 

 

你可能感兴趣的:(Python学习)