zoukankan      html  css  js  c++  java
  • 回归模型与房价预测

    from sklearn.datasets import load_boston
    boston=load_boston()
    boston.keys()
    
    
    
    print(boston.DESCR)
    
    
    
    data=boston.data
    x=data[:,5]
    y=boston.target
    
    import matplotlib.pyplot as plt
    plt.scatter(x,y)
    plt.plot(x,9*x-30)
    plt.show()

    from sklearn .linear_model import LinearRegression
    LineR=LinearRegression()
    LineR.fit(x.reshape(-1,1),y)
    w=LineR.coef_
    b=LineR.intercept_
    print(w,b)
    
    import matplotlib.pyplot as plt
    plt.scatter(x,y)
    plt.plot(x,w*x+b,'r')
    plt.show()
    data=boston.data
    x=data[:,5]
    y=boston.target
    import matplotlib.pyplot as plt
    plt.scatter(x,y)
    plt.plot(x,w*x+b)
    plt.show()
    
    from sklearn.linear_model import LinearRegression
    LineR=LinearRegression()
    LineR.fit(x.reshape(-1,1),y)
    w=LineR.coef_
    b=LineR.intercept_
    import matplotlib.pyplot as plt
    x=boston.data[:,12].reshape(-1,1)
    y=boston.target
    plt.figure(figsize=(10,6))
    plt.scatter(x,y)
    
    
    from sklearn.linear_model import LinearRegression
    lineR=LinearRegression()
    lineR.fit(x,y)
    y_pred=lineR.predict(x)
    plt.plot(x,y_pred,'green')
    print(w,b)
    plt.show()
    
    
    from sklearn.linear_model import LinearRegression
    LineR=LinearRegression()
    LineR.fit(x.reshape(-1,1),y)
    w=LineR.coef_
    b=LineR.intercept_
    print(w,b)
    import matplotlib.pyplot as plt
    plt.scatter(x,y)
    plt.plot(x,w*x+b,'r')
    plt.show()
    
    
    
    from sklearn.preprocessing import PolynomialFeatures
    poly=PolynomialFeatures(degree=2)
    x_poly=poly.fit_transform(x)
    
    lrp=LinearRegression()
    lrp.fit(x_poly,y)
    y_ploy_pred=lrp.predict(x_poly)
    
    plt.scatter(x,y)
    plt.plot(x,y_ploy_pred,'r')
    plt.show()
    
    from sklearn.preprocessing import PolynomialFeatures
    poly=PolynomialFeatures(degree=2)
    x_poly=poly.fit_transform(x)
    lrp=LinearRegression()
    lrp.fit(x_poly,y)
    plt.scatter(x,y)
    plt.scatter(x,y_pred)
    plt.scatter(x,y_ploy_pred)
    plt.show()
        
    
    

      

    
    
    
     
  • 相关阅读:
    UVALIVE 4819 最大流
    Directx 3D编程实例:随机绘制的立体图案旋转
    PHP漏洞全解(四)-xss跨站脚本攻击
    PHP漏洞全解(三)-客户端脚本植入
    PHP漏洞全解(二)-命令注入攻击
    PHP漏洞全解(一)-PHP网站的安全性问题
    BT5下安装Metasploit4.5方法
    Ubuntu使用apt-get安装本地deb包
    Linux按照时间查找文件
    Linux系统备份与还原
  • 原文地址:https://www.cnblogs.com/ZHONGmy/p/10094889.html
Copyright © 2011-2022 走看看