zoukankan      html  css  js  c++  java
  • Graphlab Linear Regression --House Price Predict

    Graphlab:一个基于图像处理模型的开源图计算框架,GraphLab是面向机器学习的流处理并行框架

    Graphlab 安装: Python必须是64位 , virtualenv 可以不装,Graphlab  安装在python安装所在的路径我这是在D盘

    以下code运行在ipython notebook上

    code :

    import graphlab
    sales = graphlab.SFrame('D:Studypythonspydepyodpshome_datahome_data.gl')
    print sales.head(10)

    graphlab.canvas.set_target('ipynb')
    sales.show(view = 'Scatter Plot',x = 'sqft_living',y = 'price')

    #将数据分成训练和测试两部分

    training_data,test_data = sales.random_split(.8,seed = 0)

    #features是变量,选取比较单一的变量做线性规划

    sqft_model = graphlab.linear_regression.create(training_data,target = 'price',features = ['sqft_living'])

    #对单一变量建立的模型进行评测

    print test_data['price'].mean()

    print sqft_model.evaluate(test_data)

    #显示模型效果

    import matplotlib.pyplot as plt
    %matplotlib inline

    plt.plot(test_data['sqft_living'],test_data['price'],'.',test_data['sqft_living'],sqft_model.predict(test_data),'-')

    #建立新的变量元素

    my_features = ['bedrooms','bathrooms','sqft_living','sqft_lot','floors','zipcode']
    sales[my_features].show()

    sales.show(view = 'BoxWhisker Plot', x = 'zipcode' ,y= 'price')

    #由多元素建立的新模型

    my_features_model = graphlab.linear_regression.create(training_data,target = 'price',features = my_features

    #显示新模型效果评估

    print sqft_model.evaluate(test_data)
    print my_features_model.evaluate(test_data)

    #两个模型显示对比

    plt.plot(test_data['sqft_living'],test_data['price'],'.',test_data['sqft_living'],sqft_model.predict(test_data),
    '-',test_data['sqft_living'],my_features_model.predict(test_data),'*')

  • 相关阅读:
    [考试反思]0421省选模拟76:学傻
    [考试反思]0420省选模拟75:安在
    [考试反思]0418省选模拟74:杂枝
    [考试反思]0417省选模拟73:纠结
    [考试反思]0416省选模拟72:停滞
    [考试反思]0415省选模拟71:限制
    [考试反思]0414省选模拟70:阻塞
    [考试反思]0413省选模拟69:遗弃
    [考试反思]0411省选模拟68:毒瘤
    [考试反思]0410省选模拟67:迷惑
  • 原文地址:https://www.cnblogs.com/lxxlovekang/p/5859400.html
Copyright © 2011-2022 走看看