美文网首页
sklearn_NNmodel

sklearn_NNmodel

作者: Lonelyroots | 来源:发表于2023-01-30 22:15 被阅读0次

    sklearn_NNmodel

    from sklearn.neural_network import MLPClassifier
    from sklearn.neural_network import MLPRegressor
    import numpy as np
    
    X = np.array([[0.,0.],
                  [1.,1.]])
    y = np.array([0,1])
    print(X.shape)
    print(y.shape)
    
    clf = MLPClassifier(solver="sgd",alpha=1e-5,activation="relu",hidden_layer_sizes=(5,2),max_iter=2000,tol=1e-4,verbose=True)       # solver选择优化算法sgd(随机梯度下降),alpha正则项系数,hidden layer里用激活函数relu,hidden_layer_sizes=(5,2),2个隐藏层,分别有5个隐藏节点,2个隐藏节点,二元组:里面存2个元素的元组,max_iter最大迭代次数,tol忍受度(sklearn默认连续10次小于,停止迭代),verbose多打印一些信息
    clf.fit(X,y)
    
    # 参数项
    print([coef.shape for coef in clf.coefs_])
    print([coef for coef in clf.coefs_])
    # 截距项
    print([intercept.shape for intercept in clf.intercepts_])
    print([intercept for intercept in clf.intercepts_])
    
    predict_value = clf.predict([[2,2],
                                 [-1,-2]])
    print(predict_value)
    predict_proba = clf.predict_proba([[2.,2.],[-1.,-2.]])
    print(predict_proba)
    

    文章到这里就结束了!希望大家能多多支持Python(系列)!六个月带大家学会Python,私聊我,可以问关于本文章的问题!以后每天都会发布新的文章,喜欢的点点关注!一个陪伴你学习Python的新青年!不管多忙都会更新下去,一起加油!

    Editor:Lonelyroots

    相关文章

      网友评论

          本文标题:sklearn_NNmodel

          本文链接:https://www.haomeiwen.com/subject/inydhdtx.html