逻辑回归_训练二元分类器
程序员文章站
2022-05-26 19:00:39
...
逻辑回归_训练二元分类器
# 训练一个二元分类器
from sklearn.linear_model import LogisticRegression
from sklearn import datasets
from sklearn.preprocessing import StandardScaler
iris = datasets.load_iris()
features = iris.data[:100,:]
target = iris.target[:100]
scaler = StandardScaler()
features_standardized = scaler.fit_transform(features)
logistic_regression = LogisticRegression(random_state=0)
model = logistic_regression.fit(features_standardized, target)
# 创建样本点
new_observation = [[.5, .5, .5, .5]]
print("model.predict: {}".format(model.predict(new_observation)))
# 查看预测概率
print("model.predict_proba: {}".format(model.predict_proba(new_observation)))