from  sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LogisticRegression
from sklearn import metrics
#题目比较奇怪,计算出来的准确率是1.0结果比0.95大,但还是通过不了
def transform_three2two_cate ():
    datasets = load_iris()
    datas = datasets.data
    targets = datasets.target
    new_feat = []
    new_label = []
    for index,target in enumerate(targets):
        if target != 2:
            new_feat.append(datas[index])
            new_label.append(targets[index])
    return new_feat,new_label

def train_and_evaluate(new_feat,new_label):
    x_train, x_test, y_train, y_test = train_test_split(new_feat,new_label,train_size=0.8,shuffle=True,random_state=0)
    model = LogisticRegression()
    model.fit(x_train,y_train)
    y_predict = model.predict(x_test)

    if y_predict is not None:
        acc = metrics.accuracy_score(y_test,y_predict)
        print(acc)

new_feat,new_label = transform_three2two_cate()
train_and_evaluate(new_feat,new_label)
# print(datasets)
# x_train,x_test,y_train,y_test = train_test_split(datasets.data,datasets.target,train_size=0.7,random_state=0)
#
# results = transform_three2two_cate (x_train,y_train,x_test)
# print(results)
#
# if results is not None:
#     acc = metrics.accuracy_score(y_test,results)
#     print(round(acc,1))