• 机器学习-分类算法-逻辑回归


    # -*- 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)
  • 相关阅读:
    Linux基础优化(二)
    权限
    分页
    序列化
    forms
    redis
    Django缓存机制
    跨域问题
    Django的ORM
    模板层
  • 原文地址:https://www.cnblogs.com/xinyumuhe/p/12634573.html
Copyright © 2020-2023  润新知