zoukankan      html  css  js  c++  java
  • kaggle Partial_Dependence_Plots

    # Partial dependence plots
    # 改变单变量对最终预测结果的影响
    # 先fit出一种模型,然后取一行,不断改变某一特征,看它对最终结果的印象。
    # 但是,只使用一行不具有典型性
    # 所以对所有行执行上述操作,求均值

    import pandas as pd
    from sklearn.ensemble import GradientBoostingRegressor, GradientBoostingClassifier
    from sklearn.ensemble.partial_dependence import partial_dependence, plot_partial_dependence
    from sklearn.preprocessing import Imputer
    import matplotlib.pyplot as plt 
    
    train_path = r"C:UserscbattleDesktop	rain.csv"
    test_path = r"C:UserscbattleDesktop	est.csv"
    out_path = r"C:UserscbattleDesktopout.csv"
    
    def get_some_data():
        data = pd.read_csv(train_path)
        y = data.SalePrice
        cols_to_use = ['YearBuilt', 'GrLivArea', 'TotRmsAbvGrd']
        X = data[cols_to_use]
        my_imputer = Imputer()
        imputed_X = my_imputer.fit_transform(X)
        return imputed_X, y
        
    X, y = get_some_data()
    my_model = GradientBoostingRegressor()
    my_model.fit(X, y)
    my_plots = plot_partial_dependence(my_model, 
                                       features=[0,2], 
                                       X=X, 
                                       feature_names=cols_to_use, 
                                       grid_resolution=10)
    plt.show()
    # print('ok')
    
    # There is a function called partial_dependence to get the raw data making up this plot, rather than making the visual plot itself.
    # This is useful if you want to control how it is visualized using a plotting package like Seaborn. With moderate effort, you could
    # make much nicer looking plots.
  • 相关阅读:
    【poj3294】 Life Forms
    【poj3415】 Common Substrings
    【poj3693】 Maximum repetition substring
    【bzoj2034】 2009国家集训队—最大收益
    【bzoj4198】 Noi2015—荷马史诗
    【poj2406】 Power Strings
    【ural1297】 Palindrome
    【spoj SUBST1】 New Distinct Substrings
    【poj1743】 Musical Theme
    django rest framework serializers小结
  • 原文地址:https://www.cnblogs.com/cbattle/p/8830774.html
Copyright © 2011-2022 走看看