zoukankan      html  css  js  c++  java
  • sklearn.linear_model.LinearRegresion学习

    sklearn线性模型之线性回归

    查看官网 https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LinearRegression.html

    1.实例化:

    a=LinearRegression()
    
    参数默认:
    fit_intercept=True, normalize=False, copy_X=True, n_jobs=None
    fit_intercept:是否存在截距,默认存在
    normalize:标准化开关,默认关闭
    copy_X
    n_jobs

    2.方法:

    #输入数据,输入x,y数据,其中参sample_weight数是指每条测试数据的权重,以array形式传入
    fit(X, y[, sample_weight])    Fit linear model.
    #
    
    get_params([deep])    Get parameters for this estimator.

    #模型预测 predict(X) Predict using the linear model

    #计算评分 score(X, y[, sample_weight]) Returns the coefficient of determination R
    ^2 of the prediction.

    Returns the coefficient of determination R^2 of the prediction.

    The coefficient R^2 is defined as (1 - u/v), where u is the residual sum of squares ((y_true - y_pred) ** 2).sum() and v is the total sum of squares ((y_true - y_true.mean()) ** 2).sum(). The best possible score is 1.0 and it can be negative (because the model can be arbitrarily worse). A constant model that always predicts the expected value of y, disregarding the input features, would get a R^2 score of 0.0.

    
    

    作用:返回该次预测的系数R2    

    
    

      其中R=(1-u/v)。

    
    

      u=((y_true - y_pred) ** 2).sum()     v=((y_true - y_true.mean()) ** 2).sum()

    其中可能得到的最好的分数是1,并且可能是负值(因为模型可能会变得更加糟糕)。当一个模型不论输入何种特征值,其总是输出期望的y的时候,此时返回0。

    
    
    set_params(
    **params) Set the parameters of this estimator.

    3.回归系数与截距

    #回归系数
    coef_
    #截距
    intercept_
  • 相关阅读:
    BZOJ 3626: [LNOI2014]LCA(树链剖分+离线处理)
    python备用
    STL的使用。。备忘
    DP专题
    任务
    hdu 网络流题集
    hdu KM匹配题集
    hdu 差分约束题集
    hdu 2sat题集
    Codeforces Round #261 (Div. 2)
  • 原文地址:https://www.cnblogs.com/students/p/10651276.html
Copyright © 2011-2022 走看看