# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import matplotlib.pyplot as plt import numpy as np from sklearn.model_selection import train_test_split from sklearn import datasets, linear_model def laod_data(): iris=datasets.load_iris() X_train=iris.data y_train=iris.target return train_test_split(X_train,y_train, test_size=0.3,random_state=0,stratify=y_train)#stratify分层 def test_LogisticRegression(*data): X_train,X_test,y_train,y_test=data regr=linear_model.LogisticRegression(solver='liblinear') regr.fit(X_train,y_train) print('Coefficients:%s, intercept %s'%(regr.coef_,regr.intercept_)) print("Score:%.2f"%regr.score(X_test,y_test)) if __name__=='__main__': X_train,X_test,y_train,y_test=laod_data() test_LogisticRegression(X_train,X_test,y_train,y_test)
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:机器学习-分类算法-逻辑回归 - Python技术站