要注意在LogisticRegression中的solver,裡頭可以選‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’, ‘saga’,官方文件有解釋(官方文件)
from sklearn.model_selection import train_test_split
from sklearn import datasets
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import accuracy_score
bc = datasets.load_breast_cancer() #load進breast_cancer的資料庫
X = bc.data
y = bc.target
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3)
clf = LogisticRegression(random_state=0, solver='lbfgs',
multi_class='multinomial').fit(X_train, y_train) #{‘newton-cg’, ‘lbfgs’, ‘liblinear’, ‘sag’, ‘saga’} 有各種演算法可以選擇
y_result = clf.predict(X_test)
y_proba = clf.predict_proba(X_test)
print(y_proba)
accuracy_score(y_test, y_result)
print("Number of mislabeled points out of a total %d points : %d"% (bc.data.shape[0],(y_test != y_result).sum()))